FIX: Don't try to focus on a missing element (#11766)

Replacing 3 imports and flawed fragile logic with a single html attribute 💆
This commit is contained in:
Jarek Radosz
2021-01-20 15:02:27 +01:00
committed by GitHub
parent a9dfc5a547
commit d6aadf60bd
2 changed files with 2 additions and 14 deletions

View File

@ -1,16 +1,12 @@
import discourseComputed, {
observes,
on,
} from "discourse-common/utils/decorators";
import Category from "discourse/models/category"; import Category from "discourse/models/category";
import Component from "@ember/component"; import Component from "@ember/component";
import I18n from "I18n"; import I18n from "I18n";
import bootbox from "bootbox"; import bootbox from "bootbox";
import { bufferedProperty } from "discourse/mixins/buffered-content"; import { bufferedProperty } from "discourse/mixins/buffered-content";
import discourseComputed from "discourse-common/utils/decorators";
import { isEmpty } from "@ember/utils"; import { isEmpty } from "@ember/utils";
import { or } from "@ember/object/computed"; import { or } from "@ember/object/computed";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import { schedule } from "@ember/runloop";
export default Component.extend(bufferedProperty("host"), { export default Component.extend(bufferedProperty("host"), {
editToggled: false, editToggled: false,
@ -19,14 +15,6 @@ export default Component.extend(bufferedProperty("host"), {
editing: or("host.isNew", "editToggled"), editing: or("host.isNew", "editToggled"),
@on("didInsertElement")
@observes("editing")
_focusOnInput() {
schedule("afterRender", () => {
this.element.querySelector(".host-name").focus();
});
},
@discourseComputed("buffered.host", "host.isSaving") @discourseComputed("buffered.host", "host.isSaving")
cantSave(host, isSaving) { cantSave(host, isSaving) {
return isSaving || isEmpty(host); return isSaving || isEmpty(host);

View File

@ -1,7 +1,7 @@
{{#if editing}} {{#if editing}}
<td class="editing-input"> <td class="editing-input">
<div class="label">{{i18n "admin.embedding.host"}}</div> <div class="label">{{i18n "admin.embedding.host"}}</div>
{{input value=buffered.host placeholder="example.com" enter=(action "save") class="host-name"}} {{input value=buffered.host placeholder="example.com" enter=(action "save") class="host-name" autofocus=true}}
</td> </td>
<td class="editing-input"> <td class="editing-input">
<div class="label">{{i18n "admin.embedding.class_name"}}</div> <div class="label">{{i18n "admin.embedding.class_name"}}</div>