From ad2c0aaee3ce51126e592309f93601198ff6a266 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 14 Jul 2022 02:59:33 +0200 Subject: [PATCH] DEV: Fix submit-on-enter and de-jQ two components (#17484) --- .../components/screened-ip-address-form.js | 31 ++++++----------- .../addon/components/watched-word-form.js | 34 ++++++------------- .../components/screened-ip-address-form.hbs | 2 +- .../components/watched-word-form.hbs | 2 +- 4 files changed, 24 insertions(+), 45 deletions(-) diff --git a/app/assets/javascripts/admin/addon/components/screened-ip-address-form.js b/app/assets/javascripts/admin/addon/components/screened-ip-address-form.js index 95ed9edfe81..ae965dd26e9 100644 --- a/app/assets/javascripts/admin/addon/components/screened-ip-address-form.js +++ b/app/assets/javascripts/admin/addon/components/screened-ip-address-form.js @@ -1,4 +1,4 @@ -import discourseComputed, { on } from "discourse-common/utils/decorators"; +import discourseComputed from "discourse-common/utils/decorators"; import Component from "@ember/component"; import I18n from "I18n"; import ScreenedIpAddress from "admin/models/screened-ip-address"; @@ -17,6 +17,7 @@ import { schedule } from "@ember/runloop"; **/ export default Component.extend({ + tagName: "form", classNames: ["screened-ip-address-form", "inline-form"], formSubmitted: false, actionName: "block", @@ -60,33 +61,23 @@ export default Component.extend({ this.setProperties({ ip_address: "", formSubmitted: false }); this.action(ScreenedIpAddress.create(result.screened_ip_address)); schedule("afterRender", () => - this.element.querySelector(".ip-address-input").focus() + this.element.querySelector("input").focus() ); }) .catch((e) => { this.set("formSubmitted", false); - const msg = - e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors - ? I18n.t("generic_error_with_reason", { - error: e.jqXHR.responseJSON.errors.join(". "), - }) - : I18n.t("generic_error"); + const msg = e.jqXHR.responseJSON?.errors + ? I18n.t("generic_error_with_reason", { + error: e.jqXHR.responseJSON.errors.join(". "), + }) + : I18n.t("generic_error"); bootbox.alert(msg, () => - this.element.querySelector(".ip-address-input").focus() + schedule("afterRender", () => + this.element.querySelector("input").focus() + ) ); }); } }, }, - - @on("didInsertElement") - _init() { - schedule("afterRender", () => { - $(this.element.querySelector(".ip-address-input")).keydown((e) => { - if (e.key === "Enter") { - this.send("submit"); - } - }); - }); - }, }); diff --git a/app/assets/javascripts/admin/addon/components/watched-word-form.js b/app/assets/javascripts/admin/addon/components/watched-word-form.js index 7bdd3138de4..cd5b2e42d07 100644 --- a/app/assets/javascripts/admin/addon/components/watched-word-form.js +++ b/app/assets/javascripts/admin/addon/components/watched-word-form.js @@ -1,7 +1,4 @@ -import discourseComputed, { - observes, - on, -} from "discourse-common/utils/decorators"; +import discourseComputed, { observes } from "discourse-common/utils/decorators"; import Component from "@ember/component"; import I18n from "I18n"; import WatchedWord from "admin/models/watched-word"; @@ -11,6 +8,7 @@ import { isEmpty } from "@ember/utils"; import { schedule } from "@ember/runloop"; export default Component.extend({ + tagName: "form", classNames: ["watched-word-form"], formSubmitted: false, actionKey: null, @@ -95,33 +93,23 @@ export default Component.extend({ }); this.action(WatchedWord.create(result)); schedule("afterRender", () => - this.element.querySelector(".watched-word-input").focus() + this.element.querySelector("input").focus() ); }) .catch((e) => { this.set("formSubmitted", false); - const msg = - e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors - ? I18n.t("generic_error_with_reason", { - error: e.jqXHR.responseJSON.errors.join(". "), - }) - : I18n.t("generic_error"); + const msg = e.jqXHR.responseJSON?.errors + ? I18n.t("generic_error_with_reason", { + error: e.jqXHR.responseJSON.errors.join(". "), + }) + : I18n.t("generic_error"); bootbox.alert(msg, () => - this.element.querySelector(".watched-word-input").focus() + schedule("afterRender", () => + this.element.querySelector("input").focus() + ) ); }); } }, }, - - @on("didInsertElement") - _init() { - schedule("afterRender", () => { - $(this.element.querySelector(".watched-word-input")).keydown((e) => { - if (e.key === "Enter") { - this.send("submit"); - } - }); - }); - }, }); diff --git a/app/assets/javascripts/admin/addon/templates/components/screened-ip-address-form.hbs b/app/assets/javascripts/admin/addon/templates/components/screened-ip-address-form.hbs index 3bd9582d56f..55facc2a07c 100644 --- a/app/assets/javascripts/admin/addon/templates/components/screened-ip-address-form.hbs +++ b/app/assets/javascripts/admin/addon/templates/components/screened-ip-address-form.hbs @@ -3,4 +3,4 @@ - + diff --git a/app/assets/javascripts/admin/addon/templates/components/watched-word-form.hbs b/app/assets/javascripts/admin/addon/templates/components/watched-word-form.hbs index b68a9f4f610..435d44ee61d 100644 --- a/app/assets/javascripts/admin/addon/templates/components/watched-word-form.hbs +++ b/app/assets/javascripts/admin/addon/templates/components/watched-word-form.hbs @@ -27,7 +27,7 @@ {{/if}} - + {{#if this.showMessage}} {{this.message}}