采用了棱角分明的验证指令与微风阻止任何输入是无效 [英] using Angular validation directives with Breeze blocks any input that is invalid

查看:134
本文介绍了采用了棱角分明的验证指令与微风阻止任何输入是无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你(NG-MINLENGTH个,NG-最大长度,NG-模式等)添加任何角度指令进行验证,以如果发现是无效的绑定到一个微风实体它会阻止任何用户输入的输入。

If you add any of the angular directives for validation (ng-minlength, ng-maxlength, ng-pattern, etc.) to an input that is bound to a breeze entity it blocks any user input if found to be invalid.

如果从NG-模型值最初有效期它显示了,但如果你的值更改为无效输入字段被清除,该模型被设置为null,你可以,可能是没有输入任何东西开始无效。但是,如果你复制一个有效值进入该领域表现出来的。

If the value from ng-model is initially valid it shows up, but if you change the value to something invalid the input field is cleared, the model is set to null, and you can't input anything that may be initially invalid. However if you copy a valid value into the field it shows.

我会被罚款与模型值设置为空时,无效的,如果它没有清除输入的事实则prevent变化。

I would be fine with the fact that the model value is set to null when invalid if it didn't clear the input then prevent changes.

此外,我有一种感觉,无论是造成这个问题也搞乱了UI的面具。同样的事情发生那里只是没有角度验证指令。

Also I have a feeling that whatever is causing this issue is also messing up ui-mask. The same thing happens there just without the angular validation directives.

这里是一个Plunker我从我修改,以显示我的问题类似的问题中发现:
<一href=\"http://plnkr.co/edit/dVsF7GFY65a30soLL5W8?p=$p$pview\">http://plnkr.co/edit/dVsF7GFY65a30soLL5W8?p=$p$pview

here is a Plunker I found from a similar question that I modified to show my issue: http://plnkr.co/edit/dVsF7GFY65a30soLL5W8?p=preview

修改

很多很多个小时的研究,我确实找到了工作,虽然我不知道的任何不良副作用的解决方案后。

After many many hours of research I did find a solution that works although I am not sure of any ill side effects.

它与以未定义如果失败,任何验证,因为它使得它的解析器方式,通过$和$格式化首先通过设置$ modelValue如何角做验证的事情。

It has to do with how angular does validation in the first place by setting the $modelValue to 'undefined' if it fails any validators as it makes it's way through $parsers and $formatters.

我发现这个code在角(行16331),获取每个角度验证名为:

I found this code in Angular (line 16331) that gets called by each angular validator:

function validate(ctrl, validatorName, validity, value){
  ctrl.$setValidity(validatorName, validity);
  return validity ? value : undefined;
}

我改变了它回到价值,而不是未定义:

I changed it to return 'value' instead of 'undefined':

function validate(ctrl, validatorName, validity, value){
      ctrl.$setValidity(validatorName, validity);

      return value;
    }

角仍设置正确验证。虽然我知道这是不是最好的解决方案,甚至是一个很好的一个。

Angular still sets validation correctly. Although I am sure this isn't the best solution or even a good one.

我怀疑,当角套$ modelValue为不确定,那么微风看到,该模型已经改变和更新,然后更新模型,然后清除输入等等...或者类似的东西在实体问题就出现了。 ..

I suspect the problem arises when Angular sets $modelValue to 'undefined' then Breeze sees that the model has changed and updates the entity which then updates the model which then clears the input and so forth... Or something like that...

我觉得这是有帮助的,我的追求。也许这将有助于你一个知道远不止我一个< href=\"https://github.com/angular/angular.js/issues/1412\">https://github.com/angular/angular.js/issues/1412

I found this to be helpful in my quest. Maybe it will be helpful to one of you that knows much more than I https://github.com/angular/angular.js/issues/1412

推荐答案

角1.3.0-RC.1推出的<$ C $使用 allowInvalid 选项C> ngModelOptions 指令。它本质上是在行16331.该选项指示角,让无效的表单输入被写入到$范围OP的黑客的形式化,整齐地解决问题。

Angular 1.3.0-rc.1 introduced the allowInvalid option for use with the ngModelOptions directive. It is essentially a formalization of the OP's hack at line 16331. The option instructs Angular to allow invalid form inputs to be written to $scope, and solves the problem neatly.

用法:

<input type="email" ng-model-options="{allowInvalid: true}" ng-model="my_breeze_model.email"/>

有关详情请参阅此功能要求: https://github.com/angular/ angular.js /问题/ 8290

这篇关于采用了棱角分明的验证指令与微风阻止任何输入是无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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