0

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

kipris
  • 2,899
  • 3
  • 20
  • 28

1 Answers1

1

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.

Nico
  • 574
  • 1
  • 4
  • 19
  • Could you advice me something to solve this problem? – kipris May 25 '16 at 08:37
  • 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 May 25 '16 at 08:54
  • Do you know how to get the length of the loaded file? Something like this: $scope.userInfo.loadedFile.length() don't work :( – kipris May 25 '16 at 08:55
  • And I can't use ngFileUpload because I use another bootstrap plugin to stylize the input file. – kipris May 25 '16 at 08:56
  • I solved my problem. I used ng-if and I don't need dynamically add the attributes. Just add them in input tag. – kipris May 26 '16 at 06:01