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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Could you advice me something to solve this problem?
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.
Do you know how to get the length of the loaded file? Something like this: $scope.userInfo.loadedFile.length() don't work :(
And I can't use ngFileUpload because I use another bootstrap plugin to stylize the input file.
I solved my problem. I used ng-if and I don't need dynamically add the attributes. Just add them in input tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.