In the process of building a component with multiple select type inputs, each containing required options. When a required field is selected, it is removed from the 'requiredFields' array and added to the 'requiredFieldsRemoved' array. If a non-required option is chosen instead, the deleted object needs to be moved back to the 'requiredFields' array.
To accomplish this, I have included an ng-change directive on the select input to capture the changed object. Now, I need to track the previous states of these changes for each select option.
//@Param publicationObject: change object from UI
$scope.itemValue = function (publicationObject) {
// using lodash to find the index
var idx = lodash.findKey($scope.requiredFields, {
name: publicationObject.name
});
// Check if the object has undergone previous changes.
// If it has, check if its status matches any object in 'requiredFieldsRemoved'
// Push it back into 'requiredFields' array, otherwise do nothing.
if( idx !== undefined ) {
$scope.requiredFields.splice(idx, 1);
requiredFieldsRemoved.push(publicationObject);
}
};
How can I implement tracking of these previous statuses?