角质材料md-select验证问题
我在表单上有几个md-select下拉列表,其中很多都有验证。验证正常工作在所有的下拉菜单,除了以下,这并不妨碍形式从提交如果空:角质材料md-select验证问题
<md-input-container class="form-input-container"
flex="15">
<label>NDRA*</label>
<md-select id="registration-information-ndra"
name="ndra"
ng-model="vm.registration.code"
ng-class="{'validation-error': newForm.ndra.$error.required && newForm.$submitted}"
ng-required="vm.validation.ndra">
<md-option ng-repeat="code in vm.dropdowns.codes"
value="{{code}}">
{{code}}
</md-option>
</md-select>
</md-input-container>
vm.validation.ndra计算结果为真实的,所以我知道这不是问题。如果我看VS工作选择选项newForm.ndra的值,如newForm.submissionDate,我得到如下:
newForm.ndra: {"$viewValue":"p","$modelValue":"p","$validators":{},"$asyncValidators":{},"$parsers":[],"$formatters":[],"$viewChangeListeners":[],"$untouched":true,"$touched":false,"$pristine":true,"$dirty":false,"$valid":true,"$invalid":false,"$error":{},"$name":"ndra","$options":null}
注册类型(验证工作):
<md-input-container class="form-input-container padded-input md-block"
flex-gt-sm="">
<label>Type of Registration*</label>
<md-select id="registration-information-type"
name="registrationType"
ng-model="vm.registration.type"
ng-class="{'validation-error': newForm.registrationType.$error.required && newForm.$submitted}"
ng-required="vm.validation.registrationType">
<md-option ng-repeat="type in vm.dropdowns.types"
value="{{type}}">
{{type}}
</md-option>
</md-select>
</md-input-container>
{"$validators":{},"$asyncValidators":{},"$parsers":[],"$formatters":[],"$viewChangeListeners":[],"$untouched":true,"$touched":false,"$pristine":true,"$dirty":false,"$valid":false,"$invalid":true,"$error":{"required":true},"$name":"registrationType","$options":null}
想通了。在我的控制器代码深处,控制器正在被实例化,然后this.registration.code
被设置为P
,所以ndra下拉列表的模型已经有了一个值。
我在想你的vm.validation.ndra
正在返回与你的vm.validation.registrationType
返回的相反。所以选择不是必需的。如果你看一下返回什么
...
国家药品管理机构
"$valid":true,"$invalid":false
与
注册类型
"$valid":false,"$invalid":true
它们完全相反。
,你应该检查,以确保您得到正确的truthy在vm.validation.ndra
这没有奏效。我在原始文章中添加了更多关于表单输入值的信息。 –
改变了我的回答 – Malachi
我检查了'vm.validation.ndra'和'vm.validation.registrationType' - 它们都返回true。 –
就值更改为false
在ng-required
,看看下面的结果在下面的链接。我认为vm.validation.ndra
返回false
。 http://codepen.io/next1/pen/WwoyWG
您能否提供有关此问题的更多信息?你有缺省选择还是空的选择? – Malachi
您是否也可以显示您列出的其他选项的标记? – Malachi
刚刚加了标记 –