Fix submitting TagDiscussionModal via enter key

The DOM submit method doesn't raise a `submit` event (https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit), so submitting the form this way just refreshed the page (default HTML form behavior). The recommended fix (and the one implemented here) is to simulate a button-triggered submission.

Fixes https://github.com/flarum/core/issues/2595
This commit is contained in:
Alexander Skvortsov 2021-02-07 01:38:39 -05:00
parent 7f14e72626
commit 9c77d677c6

View File

@ -247,7 +247,9 @@ export default class TagDiscussionModal extends Modal {
// Ctrl + Enter submits the selection, just Enter completes the current entry
if (e.metaKey || e.ctrlKey || this.selected.indexOf(this.index) !== -1) {
if (this.selected.length) {
this.$('form').submit();
// The DOM submit method doesn't emit a `submit event, so we
// simulate a manual submission so our `onsubmit` logic is run.
this.$('button[type="submit"]').click();
}
} else {
this.getItem(this.index)[0].dispatchEvent(new Event('click'));