Trying to create an array of distinct values through Schema Form appears to be a challenging task.
To simplify, let's examine this basic unique validator:
$scope.validateUnique = function(value) {
console.log('running validation');
var sameName = $scope.model.NoDuplicate.filter(function(item) {
return item.key === value;
});
return sameName.length < 2;
}
Go to this Fiddle link and open your console.
Step 1: Add a new item named 1.
Step 2: Introduce a new item called 12.
Step 3: Insert a new entry labeled 123.
Step 4: Include a new item as 1234.
Everything seems fine up to this point.
Step 5: Modify the first item (1) to 1234, triggering an error message.
Step 6: Delete the last item in order to reestablish uniqueness for the initial item. Unfortunately, nothing happens. The array does not undergo revalidation upon removal of an item or when the submit button is clicked, which should trigger form validation.
Is this issue due to my mistake? Is there an error in my code example? Or could it indicate a bug in Schema-Form? How can I ensure the array is revalidated after removing an item or submitting the form? Thank you!