Skip to content

Commit

Permalink
fix: AutoSubmitFormController - don't trigger a synthetic 'submit' ev…
Browse files Browse the repository at this point in the history
…ent when using `.requestSubmit()` as that fires it's own event unlike `.submit()`
  • Loading branch information
Sub-Xaero committed Aug 5, 2021
1 parent d9eaa98 commit e40b09b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/controllers/forms/auto_submit_form_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ export class AutoSubmitFormController extends BaseController {
}

private submit() {
// Trigger synthetic "submit" event on form to trigger the UJS submission handler
this.dispatch(this.el, "submit");

// If element is not handled by UJS, just submit
if (!this.el.dataset.remote) {
let el = this.el as HTMLFormElement;
if (el.requestSubmit && this._mode == 'request') {
el.requestSubmit();
} else {
let el = this.el as HTMLFormElement;
if (el.requestSubmit && this._mode == 'request') {
// .requestSubmit() fires a normal form submission. Including event, and all validations
el.requestSubmit();
} else {
// If element is not handled by UJS, just submit
if (!this.el.dataset.remote) {
// .submit() does not fire an event, make sure all event handlers still run
this.dispatch(this.el, "submit");
el.submit();
} else {
// Trigger synthetic "submit" event on form to trigger the UJS submission handler
this.dispatch(this.el, "submit");
}
}
}
Expand Down

0 comments on commit e40b09b

Please sign in to comment.