From 0420c56a9b040a5867589d74585f649ccfda9dc2 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 27 Sep 2021 13:42:57 -0400 Subject: [PATCH] Afform - Set default values from URL with or without field prefix For input forms, either of these will work: #?first_name=Bob #?Individual1.first_name=Bob For search forms, the display name is used as the field prefix (and range values are separated with a dash). Either of these will work: #?total_amount=500-1000 #?MySearchDisplay.total_amount=500-1000 Note that this assumes the main search entity is Contribution. For joins, the name of the join is required e.g. #?Contribution_Contact.first_name=Bob --- ext/afform/core/ang/af/afField.component.js | 6 +++++- ext/afform/core/ang/af/afFieldset.directive.js | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ext/afform/core/ang/af/afField.component.js b/ext/afform/core/ang/af/afField.component.js index df50f547bc6c..60d41c0cdf8f 100644 --- a/ext/afform/core/ang/af/afField.component.js +++ b/ext/afform/core/ang/af/afField.component.js @@ -97,10 +97,14 @@ var index = ctrl.getEntityIndex(); uniquePrefix = entityName + (index ? index + 1 : '') + (joinEntity ? '.' + joinEntity : '') + '.'; } - // Set default value based on url + // Set default value from url with uniquePrefix + fieldName if (urlArgs && urlArgs[uniquePrefix + ctrl.fieldName]) { setValue(urlArgs[uniquePrefix + ctrl.fieldName]); } + // Set default value from url with fieldName only + else if (urlArgs && urlArgs[ctrl.fieldName]) { + $scope.dataProvider.getFieldData()[ctrl.fieldName] = urlArgs[ctrl.fieldName]; + } // Set default value based on field defn else if (ctrl.defn.afform_default) { setValue(ctrl.defn.afform_default); diff --git a/ext/afform/core/ang/af/afFieldset.directive.js b/ext/afform/core/ang/af/afFieldset.directive.js index 273651fe648c..4525f0205489 100644 --- a/ext/afform/core/ang/af/afFieldset.directive.js +++ b/ext/afform/core/ang/af/afFieldset.directive.js @@ -11,15 +11,18 @@ var self = ctrls[0]; self.afFormCtrl = ctrls[1]; }, - controller: function($scope) { + controller: function($scope, $element) { var ctrl = this, localData = []; this.getData = function() { return ctrl.afFormCtrl ? ctrl.afFormCtrl.getData(ctrl.modelName) : localData; }; + // Get name of afform entity or search display this.getName = function() { - return this.modelName; + return this.modelName || + // If there is no Afform entity, get the name of embedded search display + $element.find('[search-name][display-name]').attr('display-name'); }; this.getEntityType = function() { return this.afFormCtrl.getEntity(this.modelName).type;