From: Coleman Watts Date: Mon, 27 Sep 2021 16:02:59 +0000 (-0400) Subject: Afform - ensure default value data type matches input type X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=77e3800b40fd7622371d22b7d7c475397b2287c7;p=civicrm-core.git Afform - ensure default value data type matches input type --- diff --git a/ext/afform/core/ang/af/afField.component.js b/ext/afform/core/ang/af/afField.component.js index cbfd84d826..df50f547bc 100644 --- a/ext/afform/core/ang/af/afField.component.js +++ b/ext/afform/core/ang/af/afField.component.js @@ -99,16 +99,36 @@ } // Set default value based on url if (urlArgs && urlArgs[uniquePrefix + ctrl.fieldName]) { - $scope.dataProvider.getFieldData()[ctrl.fieldName] = urlArgs[uniquePrefix + ctrl.fieldName]; + setValue(urlArgs[uniquePrefix + ctrl.fieldName]); } // Set default value based on field defn else if (ctrl.defn.afform_default) { - $scope.dataProvider.getFieldData()[ctrl.fieldName] = ctrl.defn.afform_default; + setValue(ctrl.defn.afform_default); } }); - }; + // Set default value; ensure data type matches input type + function setValue(value) { + if (ctrl.defn.input_type === 'Number' && ctrl.defn.search_range) { + if (!_.isPlainObject(value)) { + value = { + '>=': +(('' + value).split('-')[0] || 0), + '<=': +(('' + value).split('-')[1] || 0), + }; + } + } else if (ctrl.defn.input_type === 'Number') { + value = +value; + } else if (ctrl.defn.search_range && !_.isPlainObject(value)) { + value = { + '>=': ('' + value).split('-')[0], + '<=': ('' + value).split('-')[1] || '', + }; + } + + $scope.dataProvider.getFieldData()[ctrl.fieldName] = value; + } + // Get the repeat index of the entity fieldset (not the join) ctrl.getEntityIndex = function() { // If already in a join repeat, look up the outer repeat