Skip to content

Commit

Permalink
SEEDS-498 temporary workaround for range init on draft load
Browse files Browse the repository at this point in the history
  • Loading branch information
nmandrescu committed Mar 19, 2021
1 parent 9d89769 commit fa522fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
17 changes: 0 additions & 17 deletions public/js/src/enketo-webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
16 changes: 16 additions & 0 deletions public/js/src/module/controller-webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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
Expand Down

0 comments on commit fa522fb

Please sign in to comment.