multi-valued input validation support #12996
Description
ngModelController
supports $setValidity(validationErrorKey, isValid)
but isValid
is a boolean which would not provide enough information if the model value consists of multiple values or an array of values.
Consider we have an <input type="file" multiple ng-model="files" ngf-max-size="1MB">
(from https://github.com/danialfarid/ng-file-upload) the validation will happen on a list of files and if SOME of them are invalid for example exceed the maximum file size then just setting the validity of max-size
to true
or false
won't be enough since user has no clue which file is causing this error.
So I would suggest to allow an object instead of a boolean for $serValidity
so for example for the above scenario I could call $setValidity('maxSize', [invalidFile1, invalidFile2, ...])
for the invalid files in user selection and the user can show the appropriate error on the form:
<i ng-repeat="invalidFile in form.file.$error.maxSize">File {{invalidFile.name}} is too big</i>
This could also be helpful in case the validation is a time consuming process and generate a list of errors or informative message on how to fix the error depending on the model value.