Skip to content

Commit

Permalink
Afform - Set default values from URL with or without field prefix
Browse files Browse the repository at this point in the history
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
  • Loading branch information
colemanw committed Oct 3, 2021
1 parent 9d6c81e commit 0420c56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ext/afform/core/ang/af/afField.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions ext/afform/core/ang/af/afFieldset.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0420c56

Please sign in to comment.