Skip to content

Commit

Permalink
Afform - Fix clearing fields when deselecting existing entity
Browse files Browse the repository at this point in the history
This regressed in e2c263c
  • Loading branch information
colemanw committed Aug 22, 2023
1 parent 7877d13 commit 1d27a34
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ext/afform/core/ang/af/afForm.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
// With no arguments this will prefill the entire form based on url args
// With selectedEntity, selectedIndex & selectedId provided this will prefill a single entity
this.loadData = function(selectedEntity, selectedIndex, selectedId, selectedField) {
var toLoad = 0,
params = {name: ctrl.getFormMeta().name, args: {}};
let toLoad = false;
const params = {name: ctrl.getFormMeta().name, args: {}};
// Load single entity
if (selectedEntity) {
toLoad = 1;
toLoad = !!selectedId;
params.matchField = selectedField;
params.args[selectedEntity] = {};
params.args[selectedEntity][selectedIndex] = selectedId;
Expand All @@ -57,7 +57,7 @@
args = _.assign({}, $scope.$parent.routeParams || {}, $scope.$parent.options || {});
_.each(schema, function (entity, entityName) {
if (args[entityName] || entity.actions.update) {
toLoad++;
toLoad = true;
}
if (args[entityName] && typeof args[entityName] === 'string') {
args[entityName] = args[entityName].split(',');
Expand All @@ -79,10 +79,11 @@
}
// Clear existing contact selection
else if (selectedEntity) {
data[selectedEntity][selectedIndex].fields = {};
if (data[selectedEntity][selectedIndex].joins) {
data[selectedEntity][selectedIndex].joins = {};
}
// Delete object keys without breaking object references
Object.keys(data[selectedEntity][selectedIndex].fields).forEach(key => delete data[selectedEntity][selectedIndex].fields[key]);
// Fill pre-set values
angular.merge(data[selectedEntity][selectedIndex].fields, _.cloneDeep(schema[selectedEntity].data || {}));
data[selectedEntity][selectedIndex].joins = {};
}
};

Expand Down

0 comments on commit 1d27a34

Please sign in to comment.