parsley.js 条件表单验证
parsley.js conditional form validation
我将 MVC 与 Angular JS 一起使用,并使用 parsley.js(版本 2.6.2)
进行验证
当我选中复选框 1 时,提交表单时应该需要 2 个文本框(txtCustomer、txtchk1 和 txtchk2)
当点击复选框 2 时,文本框 (txtCustomer & txtchk3) 应该是必需的
我的表格如下。
<input type="checkbox" id="chkCreditCard" ng-model="dvCreditCard" ng-change="alert1(dvCreditCard)" />
Check1 required
<input ng-model="" type="text" class="form-control" id="txtchk1" placeholder="requied if checkbox1 checked" />
<input ng-model="" type="text" class="form-control" id="txtchk2" placeholder="requied if checkbox1 checked" />
<input type="checkbox" id="chkCheque" ng-model="dvCheque" />
Check2 required
<input ng-model="" type="text" class="form-control" id="txtchk3" placeholder="requied if checkbox2 checked" />
</form>
您可以在此处使用 ng-required
指令根据表达式
使字段成为必填项
<input type="checkbox" id="chkCreditCard" ng-model="dvCreditCard"/>
Check1 required
<input ng-model="texchk1" ng-required="dvCreditCard" type="text"
class="form-control" id="txtchk1" placeholder="requied if checkbox1 checked" />
<input ng-model="txtchk2" type="text" class="form-control" ng-required="dvCreditCard"
id="txtchk2" placeholder="requied if checkbox1 checked" />
<input type="checkbox" id="chkCheque" ng-required="dvCreditCard" ng-model="dvCheque" />
Check2 required
<input ng-model="txtchk3" type="text" ng-required="dvCheque" class="form-control" id="txtchk3" placeholder="requied if checkbox2 checked" />
我将 MVC 与 Angular JS 一起使用,并使用 parsley.js(版本 2.6.2)
进行验证当我选中复选框 1 时,提交表单时应该需要 2 个文本框(txtCustomer、txtchk1 和 txtchk2)
当点击复选框 2 时,文本框 (txtCustomer & txtchk3) 应该是必需的
我的表格如下。
<input type="checkbox" id="chkCreditCard" ng-model="dvCreditCard" ng-change="alert1(dvCreditCard)" />
Check1 required
<input ng-model="" type="text" class="form-control" id="txtchk1" placeholder="requied if checkbox1 checked" />
<input ng-model="" type="text" class="form-control" id="txtchk2" placeholder="requied if checkbox1 checked" />
<input type="checkbox" id="chkCheque" ng-model="dvCheque" />
Check2 required
<input ng-model="" type="text" class="form-control" id="txtchk3" placeholder="requied if checkbox2 checked" />
</form>
您可以在此处使用 ng-required
指令根据表达式
<input type="checkbox" id="chkCreditCard" ng-model="dvCreditCard"/>
Check1 required
<input ng-model="texchk1" ng-required="dvCreditCard" type="text"
class="form-control" id="txtchk1" placeholder="requied if checkbox1 checked" />
<input ng-model="txtchk2" type="text" class="form-control" ng-required="dvCreditCard"
id="txtchk2" placeholder="requied if checkbox1 checked" />
<input type="checkbox" id="chkCheque" ng-required="dvCreditCard" ng-model="dvCheque" />
Check2 required
<input ng-model="txtchk3" type="text" ng-required="dvCheque" class="form-control" id="txtchk3" placeholder="requied if checkbox2 checked" />