From df28f95db55b94417196dee9403c01b39232e5cb Mon Sep 17 00:00:00 2001 From: dewa Date: Thu, 11 Jan 2024 23:36:49 +0800 Subject: [PATCH 1/2] OC-22077 Query widget appearing when clicking add repeat group button in form --- public/js/src/module/form.js | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/public/js/src/module/form.js b/public/js/src/module/form.js index 7c53fd01..1ed44ad8 100644 --- a/public/js/src/module/form.js +++ b/public/js/src/module/form.js @@ -1,6 +1,8 @@ // Extend the Enketo Core Form class, and expose it for local testing. import { Form, FormModel } from 'enketo-core'; import events from 'enketo-core/src/js/event'; +import { scrollIntoViewIfNeeded } from 'enketo-core/src/js/dom-utils'; +import $ from 'jquery'; import config from 'enketo/config'; import gui from './gui'; import settings from './settings'; @@ -419,5 +421,49 @@ Form.prototype.updateValidityInUi = function (control, result) { } }; +Form.prototype.goToTarget = function (target, options = {}) { + if (target) { + if (this.pages.active && !options.isPageFlip) { + // Flip to page + this.pages.flipToPageContaining($(target)); + } + // check if the target has a form control + if (target.closest('.calculation, .setvalue, .setgeopoint')) { + // It is up to the apps to decide what to do with this event. + target.dispatchEvent(events.GoToInvisible()); + } + // check if the nearest question or group is irrelevant after page flip + if (target.closest('.or-branch.disabled')) { + // It is up to the apps to decide what to do with this event. + target.dispatchEvent(events.GoToIrrelevant()); + } + + // Focus on the first non .ignore form control which is not currently readonly. + // If the element is hidden (e.g. because it's been replaced by a widget), + // the focus event will not fire, so we also trigger an applyfocus event that widgets can listen for. + let selector = + 'input:not(.ignore):not([readonly]), textarea:not(.ignore):not([readonly]), select:not(.ignore):not([readonly])'; + + // For repeat DOM, prevent focus on DN dome when all element is readonly or ignore(#733) + if (target.querySelector('.repeat-number')) { + selector = + '.question:not(.or-appearance-dn) input:not(.ignore):not([readonly]), .question:not(.or-appearance-dn) textarea:not(.ignore):not([readonly]), .question:not(.or-appearance-dn) select:not(.ignore):not([readonly])'; + } + + const input = target.querySelector(selector); + + if (input != null) { + input.focus(); + input.dispatchEvent(events.ApplyFocus()); + } + + // Scroll to element if needed. This will generally be a noop unless no + // focusable control was found (e.g. readonly question in pages mode). + scrollIntoViewIfNeeded(target); + } + + return !!target; +}; + /* eslint import/prefer-default-export: "off" */ export { Form }; From eaaa71568f99bf6cbe656c8db864998296b88a50 Mon Sep 17 00:00:00 2001 From: dewa Date: Mon, 29 Jan 2024 22:19:06 +0800 Subject: [PATCH 2/2] OC-22077 Query widget appearing when clicking add repeat group button in form(update) --- public/js/src/module/form.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/public/js/src/module/form.js b/public/js/src/module/form.js index 1ed44ad8..8f11deaf 100644 --- a/public/js/src/module/form.js +++ b/public/js/src/module/form.js @@ -441,11 +441,12 @@ Form.prototype.goToTarget = function (target, options = {}) { // Focus on the first non .ignore form control which is not currently readonly. // If the element is hidden (e.g. because it's been replaced by a widget), // the focus event will not fire, so we also trigger an applyfocus event that widgets can listen for. - let selector = - 'input:not(.ignore):not([readonly]), textarea:not(.ignore):not([readonly]), select:not(.ignore):not([readonly])'; - - // For repeat DOM, prevent focus on DN dome when all element is readonly or ignore(#733) - if (target.querySelector('.repeat-number')) { + let selector; + if (target.closest('.question')) { + selector = + 'input:not(.ignore):not([readonly]), textarea:not(.ignore):not([readonly]), select:not(.ignore):not([readonly])'; + } else { + // For repeat DOM, prevent focus on DN dome when all element is readonly or ignore(#733) selector = '.question:not(.or-appearance-dn) input:not(.ignore):not([readonly]), .question:not(.or-appearance-dn) textarea:not(.ignore):not([readonly]), .question:not(.or-appearance-dn) select:not(.ignore):not([readonly])'; }