Skip to content

Commit

Permalink
@uppy/form: move internal property to private field (#5214)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Jun 3, 2024
1 parent dbfb93f commit 7942976
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/@uppy/form/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class Form<M extends Meta, B extends Body> extends BasePlugin<
> {
static VERSION = packageJson.version

form: HTMLFormElement // TODO: make this private (or at least, mark it as readonly)
#form: HTMLFormElement

/**
* Unfortunately Uppy isn't a state machine in which we can guarantee it's
Expand Down Expand Up @@ -84,7 +84,7 @@ export default class Form<M extends Meta, B extends Body> extends BasePlugin<
}

if (this.opts.submitOnSuccess) {
this.form.requestSubmit()
this.#form.requestSubmit()
}
}

Expand Down Expand Up @@ -128,7 +128,7 @@ export default class Form<M extends Meta, B extends Body> extends BasePlugin<
this.uppy.log('[Form] Adding result to the original form:')
this.uppy.log(result)

let resultInput: HTMLInputElement | null = this.form.querySelector(
let resultInput: HTMLInputElement | null = this.#form.querySelector(
`[name="${this.opts.resultName}"]`,
)
if (resultInput) {
Expand All @@ -155,27 +155,27 @@ export default class Form<M extends Meta, B extends Body> extends BasePlugin<
resultInput.type = 'hidden'
resultInput.value = JSON.stringify([result])

this.form.appendChild(resultInput)
this.#form.appendChild(resultInput)
}

getMetaFromForm(): void {
const formMeta = getFormData(this.form)
const formMeta = getFormData(this.#form)
// We want to exclude meta the the Form plugin itself has added
// See https://github.com/transloadit/uppy/issues/1637
delete formMeta[this.opts.resultName]
this.uppy.setMeta(formMeta)
}

install(): void {
this.form = assertHTMLFormElement(findDOMElement(this.opts.target))
this.#form = assertHTMLFormElement(findDOMElement(this.opts.target))

this.form.addEventListener('submit', this.handleFormSubmit)
this.#form.addEventListener('submit', this.handleFormSubmit)
this.uppy.on('upload', this.handleUploadStart)
this.uppy.on('complete', this.handleSuccess)
}

uninstall(): void {
this.form.removeEventListener('submit', this.handleFormSubmit)
this.#form.removeEventListener('submit', this.handleFormSubmit)
this.uppy.off('upload', this.handleUploadStart)
this.uppy.off('complete', this.handleSuccess)
}
Expand Down

0 comments on commit 7942976

Please sign in to comment.