下面这条线的正确方法是什么?
ng-pattern="(true)? apply-pattern : dont-apply-pattern"我的问题是,我在不需要的时候隐藏了ng-pattern字段,但仍然不允许表单有效。
我试着禁用该字段,但没有成功。
代码是:
<input type="text" ng-hide="param.paramType == 'java.lang.boolean'"
ng-pattern="param.paramValidatePattern" class="form-control input-sm" name="paramV"
ng-model="param.paramValue" ng-required="param.paramType != 'java.lang.boolean'"
ng-disabled="param.paramType == 'java.lang.boolean'" />发布于 2015-01-15 01:18:41
看看这个特殊的条件在你的版本中是否适用...
<form name='myFormName'ng-submit="submitFormFunction()">
<input type="text" name="mySpecialPatternField" .../>在JS代码中(指令||控制器)
$scope.submitFormFunction = function(){
if( specialConditionIsMet ){
// then we don't want the pattern input to matter in form validation
$scope.myFormName.mySpecialPatternField.$setValidity('pattern', true);
}
}可能需要是假的,我不记得了,但它们被换成了你认为它们应该是的角度。
如果使用$setValidity,且对输入有多个验证(除了pattern之外,假设还有requierd ),则需要遍历$scope.myFormName.mySpecialPatternField.$error
对象来获取键,然后将每个键都设置为true;这将为每个错误将$valid设置为true,从而将表单也设置为$valid = true。
但是,这可能在您的版本中可用,也可能不可用。检查一下...
https://stackoverflow.com/questions/22017198
复制相似问题