From fa522fb375bd4bb7de2d106431790c05458cc84f Mon Sep 17 00:00:00 2001 From: nmandrescu <17854915+nmandrescu@users.noreply.github.com> Date: Fri, 19 Mar 2021 14:19:42 +0200 Subject: [PATCH] SEEDS-498 temporary workaround for range init on draft load --- public/js/src/enketo-webform.js | 17 ----------------- public/js/src/module/controller-webform.js | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/public/js/src/enketo-webform.js b/public/js/src/enketo-webform.js index 07db5687f..c6a58bbf0 100644 --- a/public/js/src/enketo-webform.js +++ b/public/js/src/enketo-webform.js @@ -236,26 +236,9 @@ function _init( formParts ) { if ( settings.print ) { gui.applyPrintStyle(); } - _initRange(); // after widgets have been initialized, localize all data-i18n elements localize( formEl ); _countChars(); return formParts; } ); } - - -/** - * temporary workaround for https://github.com/enketo/enketo-core/issues/771 - */ -function _initRange() { - const rangeEls = document.getElementsByClassName("range-widget__current"); - for (let i = 0; i < rangeEls.length; i++) { - const rangeEl = rangeEls[i]; - const labelEl = rangeEl.closest("label"); - const inputEl = labelEl === null ? null : labelEl.querySelector("input.hide"); - if (inputEl !== null && inputEl.value) { - rangeEl.innerHTML = inputEl.valueAsNumber; - } - } -} diff --git a/public/js/src/module/controller-webform.js b/public/js/src/module/controller-webform.js index 22634ed84..6e3cf0ef8 100644 --- a/public/js/src/module/controller-webform.js +++ b/public/js/src/module/controller-webform.js @@ -204,6 +204,7 @@ function _loadRecord( instanceId, confirmed ) { if ( loadErrors.length > 0 ) { throw loadErrors; } else { + _initRange(); gui.feedback( t( 'alert.recordloadsuccess.msg', { recordName: record.name } ), 2 ); @@ -220,6 +221,21 @@ function _loadRecord( instanceId, confirmed ) { } } +/** + * temporary workaround for https://github.com/enketo/enketo-core/issues/771 + */ +function _initRange() { + const rangeEls = document.getElementsByClassName("range-widget__current"); + for (let i = 0; i < rangeEls.length; i++) { + const rangeEl = rangeEls[i]; + const labelEl = rangeEl.closest("label"); + const inputEl = labelEl === null ? null : labelEl.querySelector("input.hide"); + if (inputEl !== null && inputEl.value) { + rangeEl.innerHTML = inputEl.valueAsNumber; + } + } +} + /** * Used to submit a form. * This function does not save the record in the browser storage