Skip to content
This repository was archived by the owner on Jul 1, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/validation-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ angular
// list of available published public functions of this object
validationCommon.prototype.addToValidationSummary = addToValidationSummary; // add an element to the $validationSummary
validationCommon.prototype.arrayFindObject = arrayFindObject; // search an object inside an array of objects
validationCommon.prototype.arrayRemoveObject = arrayRemoveObject; // search an object inside an array of objects and remove it from array
validationCommon.prototype.defineValidation = defineValidation; // define our validation object
validationCommon.prototype.getFormElementByName = getFormElementByName; // get the form element custom object by it's name
validationCommon.prototype.getFormElements = getFormElements; // get the array of form elements (custom objects)
Expand Down Expand Up @@ -771,6 +772,25 @@ angular
return null;
}

/** Quick function to remove an object inside an array by it's given field name and value, return and remove the object found or null
* @param Array sourceArray
* @param string searchId: search property id
* @param string searchValue: value to search
* @return object found from source array or null
*/
function arrayRemoveObject(sourceArray, searchId, searchValue) {
if (!!sourceArray) {
for (var i = 0; i < sourceArray.length; i++) {
if (sourceArray[i][searchId] === searchValue) {
var itemToRemove = sourceArray[i];
sourceArray.splice(i,1);
return itemToRemove;
}
}
}
return null;
}

/** Quick function to find all object(s) inside an array of objects by it's given field name and value, return array of object found(s) or empty array
* @param Array sourceArray
* @param string searchId: search property id
Expand Down