Trying to dynamically add validation to input file if I choose first option from select. But if I add required attribute, it still ng-valid in class. If I load file to input file, it still ng-empty.
What's wrong? http://plnkr.co/edit/pjyCULes60jWf7yqNsyB?p=preview
1 Answer
The form validation in AngularJS depends on the ngModel attribute, which doesn't work with input type=file.
To solve this, either use ngFileUpload which helps you solve other problems you'll encounter with file upload in Angular as well, or see this or that answer.
5 Comments
kipris
Could you advice me something to solve this problem?
kipris
As you can see, I added directive that creates the new attribute. The problem is in adding attribute dynamically. If I choose proper option and input file will show with adding valid-file attribute, ng-classes will not change, it stay ng-valid.
kipris
Do you know how to get the length of the loaded file? Something like this: $scope.userInfo.loadedFile.length() don't work :(
kipris
And I can't use ngFileUpload because I use another bootstrap plugin to stylize the input file.
kipris
I solved my problem. I used ng-if and I don't need dynamically add the attributes. Just add them in input tag.