I have been playing around this and couldnt get it to work. I was creating an angular form and I was able to get the validation to work when required
attribute is added to the text field. However, if a input type file
is added with required
attribution, I noticed that the $error.required
text is shown but it doesnt validation even if a file is chosen. Its still showing as invalid even after adding a file. I have created a sample in jsfiddle so you can check this out: /
Doesnt validation work for file inputs? How can I add a required option and validate it when using file select?
I have been playing around this and couldnt get it to work. I was creating an angular form and I was able to get the validation to work when required
attribute is added to the text field. However, if a input type file
is added with required
attribution, I noticed that the $error.required
text is shown but it doesnt validation even if a file is chosen. Its still showing as invalid even after adding a file. I have created a sample in jsfiddle so you can check this out: http://jsfiddle/Alien_time/kxSaz/6/
Doesnt validation work for file inputs? How can I add a required option and validate it when using file select?
Share Improve this question asked Apr 1, 2014 at 19:41 NeelNeel 9,88023 gold badges93 silver badges130 bronze badges1 Answer
Reset to default 14ngModelController doesn't currently support input type=file.
you can solve your issue with a custom directive.
app.directive('validFile',function(){
return {
require:'ngModel',
link:function(scope,el,attrs,ngModel){
el.bind('change',function(){
scope.$apply(function(){
ngModel.$setViewValue(el.val());
ngModel.$render();
});
});
}
}
});
see usage here