如何 Enable/Disable html 控件在 AngularJS 中的验证
How to Enable/Disable html controls' validation in AngularJS
我有一个单选按钮组。第一个用于 "Inside Bangladesh",第二个用于 "Outside Bangladesh"。如果我单击 "Inside Bangladesh",地址字段(文本框)不需要验证,但是如果我单击 "Outside Bangladesh",将触发地址字段所需的验证。看我下面的代码:
<ng-form id="validateReg" name="validateReg">
<div ng-class="{'has-error': validateReg.chkInside.$invalid}">
<label>
<input type="radio" id="radioInsideBD" required value="1" ng-model="chkInside" name="chkInside" />
Inside Bangladesh
</label>
<label>
<input type="radio" id="radioOutsideBD" required value="1" ng-model="chkInside" name="chkInside" />
Outside Bangladesh
</label>
</div>
<div ng-class="{'has-error': validateReg.address.$invalid}">
Address: <textarea type="text" class="form-control" ng-model="address" name="address" id="address"></textarea>
</div>
</ng-form>
<div ng-class="{'has-error': (addressRequired ? validateReg.address.$invalid : false)}">
Address: <textarea type="text" class="form-control" ng-model="address" name="address" id="address"></textarea>
</div>
您应该 set/unset addressRequired
基于所选的单选按钮。
如果选择 Inside Bangladesh
,则将其设置为 false
,否则 true
。
我有一个单选按钮组。第一个用于 "Inside Bangladesh",第二个用于 "Outside Bangladesh"。如果我单击 "Inside Bangladesh",地址字段(文本框)不需要验证,但是如果我单击 "Outside Bangladesh",将触发地址字段所需的验证。看我下面的代码:
<ng-form id="validateReg" name="validateReg">
<div ng-class="{'has-error': validateReg.chkInside.$invalid}">
<label>
<input type="radio" id="radioInsideBD" required value="1" ng-model="chkInside" name="chkInside" />
Inside Bangladesh
</label>
<label>
<input type="radio" id="radioOutsideBD" required value="1" ng-model="chkInside" name="chkInside" />
Outside Bangladesh
</label>
</div>
<div ng-class="{'has-error': validateReg.address.$invalid}">
Address: <textarea type="text" class="form-control" ng-model="address" name="address" id="address"></textarea>
</div>
</ng-form>
<div ng-class="{'has-error': (addressRequired ? validateReg.address.$invalid : false)}">
Address: <textarea type="text" class="form-control" ng-model="address" name="address" id="address"></textarea>
</div>
您应该 set/unset addressRequired
基于所选的单选按钮。
如果选择 Inside Bangladesh
,则将其设置为 false
,否则 true
。