From ac15ed8983ff3e1d78426cadabd24e7dda6927cf Mon Sep 17 00:00:00 2001 From: angus Date: Fri, 12 Mar 2021 18:02:50 +1100 Subject: [PATCH] COMPATIBILITY: core autofocus does not work with custom wizard DOM structure --- .../initializers/custom-wizard-step.js.es6 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/wizard/initializers/custom-wizard-step.js.es6 b/assets/javascripts/wizard/initializers/custom-wizard-step.js.es6 index 854c4623..5d5778f3 100644 --- a/assets/javascripts/wizard/initializers/custom-wizard-step.js.es6 +++ b/assets/javascripts/wizard/initializers/custom-wizard-step.js.es6 @@ -10,6 +10,7 @@ export default { const getUrl = requirejs("discourse-common/lib/get-url").default; const discourseComputed = requirejs("discourse-common/utils/decorators").default; const cook = requirejs("discourse/plugins/discourse-custom-wizard/wizard/lib/text-lite").cook; + const { schedule } = requirejs("@ember/runloop"); StepModel.reopen({ save() { @@ -71,9 +72,23 @@ export default { StepComponent.reopen({ classNameBindings: ["step.id"], + + autoFocus() { + schedule("afterRender", () => { + const $invalid = $( + ".wizard-field.invalid:nth-of-type(1) .wizard-focusable" + ); + + if ($invalid.length) { + return $invalid.focus(); + } + + $(".wizard-focusable:first").focus(); + }); + }, animateInvalidFields() { - Ember.run.scheduleOnce("afterRender", () => { + schedule("afterRender", () => { let $element = $(".invalid input[type=text],.invalid textarea,.invalid input[type=checkbox],.invalid .select-kit"); if ($element.length) {