与“必需”属性 - AngularJS文件输入验证不工作 [英] Validation doesnt work for File Input with 'Required' attribute- AngularJS

查看:281
本文介绍了与“必需”属性 - AngularJS文件输入验证不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩解决这个并且不可能得到它的工作。我创建一个角的形式,我能得到验证时,要求属性添加到文本领域的工作。但是,如果输入类型文件中加入要求归属,我注意到 $ error.required 文本显示,但它不验证即使选择了一个文件。它仍然显示,即使添加文件后,为无效。我已经创造了一个的jsfiddle样本,所以你可以看看这个: http://jsfiddle.net/Alien_time/ kxSaz / 6 /

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.net/Alien_time/kxSaz/6/

有关文件输入犯规审定工作?我如何添加一个必需的选项,并验证它使用文件选择什么时候?

推荐答案

ngModelController 没有按' ŧ目前支持INPUT TYPE =文件。

ngModelController 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();
        });
      });
    }
  }
});

在这里看到的用法

这篇关于与“必需”属性 - AngularJS文件输入验证不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆