I'm not really sure if this has already been answered since I really can't find the answer in other posts.
I have an array of file names (ex. [flower.jpg, rose.jpg])
that I want to validate against the chosen files from the input type=file form. This validation detects duplicates then I want to set the error validity like this "$scope.detailsForm.files.$setValidity("duplicate", true);".
The problem is "$scope.detailsForm.files"
is getting undefined but this is not the case with other input types such as "input type="text" name="username""
.
What I've noticed using AngularJS Batarang I am seeing that the scope for the "detailsForm"
contains all my inputs' "name" attribute except for my input type="file"
Also what's weird is adding "ng-model='anythingHere'"
to my input type="file"
makes the "name"
attribute exist in the "detailsForm"
scope, thus achieving my desired result.
However it really is bugging me because I really don't want to add the ng-model directive since I'm already using angular-file-upload for this.
Here's a snippet of the codes:
Controller:
if (imageArr.indexOf(uploadFilename) != -1) {
$scope.detailsForm.files.$setValidity("duplicate", true);
return;
}
else {
$scope.detailsForm.files.$setValidity("duplicate", false);
}
HTML:
input type="file" name="files" ng-file-select="onFileSelect($files)
Hope you understand my question and situation.
PS: This is actually my first time posting here in stackOverFlow since the posts here has always answered my questions. This time I really need help! Masters I need chu!