Angularjs 窗体和子窗体输入有效时启用按钮
我有以下表单,我想在其底部启用/禁用按钮,仅当表单和子表单有效时,但现在它仅使用表单输入进行验证,似乎没有使用子表单(ng表单)输入进行验证: 这是我需要的最低版本:Angularjs 窗体和子窗体输入有效时启用按钮,angularjs,ionic-framework,ionic,Angularjs,Ionic Framework,Ionic,我有以下表单,我想在其底部启用/禁用按钮,仅当表单和子表单有效时,但现在它仅使用表单输入进行验证,似乎没有使用子表单(ng表单)输入进行验证: 这是我需要的最低版本: <!-- FORM BEGINNING --> <form name="medsRefundForm" novalidate> <div class="card"> <!-- NAME --> <label class="item fields" ng-c
<!-- FORM BEGINNING -->
<form name="medsRefundForm" novalidate>
<div class="card">
<!-- NAME -->
<label class="item fields" ng-click="isKeyboardOpenToTrue()">
<input type="text"
ng-model="userName"
ng-blur="showFootBar()"
name="username"
ng-required="true"
placeholder="Nombre del titular de la poliza">
</label>
<!-- ID NUMBER -->
<label class="item fields" ng-click="isKeyboardOpenToTrue()">
<input type="number"
ng-model="idNumber"
ng-blur="showFootBar()"
ng-required="true"
name="idnum"
placeholder="Cédula / Nit">
</label>
<p>SUBFORM START</p>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
INNER SUBFORM
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<ng-form name="subform">
<!-- TITLE HOLDER NAME -->
<label class="item fields">
<input type="text" placeholder="Nombre del titular de la poliza"
ng-required="true"
ng-click="showFootBar()">
</label>
<!-- TITLE HOLDER ID NUMBER -->
<label class="item fields">
<input type="number" placeholder="Cédula / Nit"
ng-required="true"
ng-click="showFootBar()">
</label>
</ng-form>
<div class="bottom-placeholder">
</div>
</div>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I WANT TO ENABLE/DISABLE THIS BUTTON WHEN FORM IS VALID
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<div ng-hide="isKeyboardOpen">
<button class="button button-block btn-policy"
ng-disabled="!medsRefundForm.$valid"
ng-click="continueForm()">ENABLE THIS WITH VALIDATION</button>
</div>
</form>
子窗体启动
通过验证启用此选项
现在是示例的链接:
我的完整HTML类对于pastebin中的我来说是更复杂的链接:请查看您更新的演示:
您可以使用此
medsRefundForm.subform.$valid来访问子表单的有效性
,您需要以这种方式将其置于ng disabled
状态
ng-disabled="!medsRefundForm.$valid || !medsRefundForm.subform.$valid"
另外,您需要为子表单输入元素放置ng model
。你错过了那些。在向输入元素提供模型之前,角度验证不起作用。请参阅您的以下代码,您错过了型号
<input type="text" placeholder="Nombre del titular de la poliza" ng-required="true" ng-click="showFootBar()">
查看此内容以了解更多信息。非常感谢,此功能非常好,是否需要为子窗体添加DINAMICALL或在运行时添加所需的
ng
,正如您在我的完整代码中所看到的,此区域仅基于绑定到
上的toogleChecked
可用,其具有ng模型=“ToogleChecked”
因此,我希望仅当勾选了toggle时才需要最后两个输入:toggleChecked=trueWell而不是在运行时分配ng required
,您可以使用toggle值在ng disabled
处进行检查,如此ng disabled=“!medsRefundForm.$valid | |(!medsRefundForm.subform.$valid&&toggleModel)`必须为第一部分包括一个子表单:``然后另一个子表单为:``然后在启用/禁用按钮上添加:`ng disabled=“(!medsRefundForm.firstSubform.$valid&&toggleChecked)|(toggleChecked&!medsRefundForm.secondSubform.$valid)“`它终于起作用了:Dyeah谢谢你的帮助,你在爱奥尼亚问题上真的救了我一命