<div ng-show="!login.SecQuestions && !login.ResetUser">
<h3>Answer security questions</h3>
<ul>
<li>
<label>Please answer the following question(s)</label>
</li>
</ul>
<ul>
<li>
*= required field
</li>
</ul>
<ul ng-repeat="Question in login.SecurityQuestions">
<li>
{{Question.Question}}
</li>
<li>
<ng-form name="SecQuestionForm" novalidate>
<textarea name="SecurityAnswer" ng-model="Question.Answer" type="text" required></textarea>
<span style="color:red" ng-if="SecQuestionForm.SecurityAnswer.$dirty" ng-show="SecQuestionForm.SecurityAnswer.$invalid">required.</span>
</ng-form>
</li>
</ul>
<ul>
<li>
<button class="primaryButton" ng-disabled="ResetNamePass.SecQuestionForm.$invalid" ng-click="Continue_2()">Continue</button>
</li>
</ul>
</div>
ng-Form 的动态验证 启用该按钮不会验证所有三个必填字段,具体取决于最后一个Textarea的必需字段。
错误的屏幕截图
答案 0 :(得分:1)
让我们假设你有这样的形式
<form name='form'>
<input name='name'></input>
<button ng-disabled='!form.name'></button>
</form>
希望它有所帮助 演示Fiddle
答案 1 :(得分:1)
将您的ng-form放在一个表单中,然后在按钮上添加条件以获得外部表单的有效性。
<form novalidate name='form1'>
<ul ng-repeat="Question in login.SecurityQuestions">
<li>
{{Question.Question}}
</li>
<li>
<ng-form name="SecQuestionForm" novalidate>
<textarea name="SecurityAnswer" ng-model="Question.Answer" type="text" required></textarea>
<span style="color:red" ng-if="SecQuestionForm.SecurityAnswer.$dirty" ng-show="SecQuestionForm.SecurityAnswer.$invalid">required.</span>
</ng-form>
</li>
</ul>
<ul>
<li>
<button class="primaryButton" ng-disabled="!form1.$valid" ng-click="Continue_2()">Continue</button>
</li>
</ul>
</form>
只有当所有嵌套的ng-forms都有效时,外部表格才有效
答案 2 :(得分:0)
angular - Developer Guide - Forms
<form name="form" class="css-form" novalidate>
<div>
Overwritten Email:
<input type="email" ng-model="myEmail" overwrite-email name="overwrittenEmail" />
<span ng-show="form.overwrittenEmail.$error.email">This email format is invalid!</span><br>
Model: {{myEmail}}
</div>
</form>
答案 3 :(得分:0)
`<form name="frmsignIn" ng-submit="login()" novalidate >
<span class="glyphicon glyphicon-user" ></span>
<div>
<label for="email" >Email</label>
<input type="email" name="email" ng-model="userName" ng-required="true"/>
<span ng-show="frmsignIn.email.$dirty && frmsignIn.email.$error.required">*</span><span ng-show="frmsignIn.email.$dirty && frmsignIn.email.$error.email">Invalid email address</span>
</div>
<div>
<label for="password">Password</label>
<input type="password" name="password" ng-model="password" ng-required="true"/>
<span ng-show="frmsignIn.password.$dirty && frmsignIn.password.$error.required">*</span>
</div>
<div>
<button type="submit" ng-disabled="frmsignIn.$invalid" > {{buttonText}}</button>
</div>
<div>
<span ng-show="showErrorMsg">Invalid Email Address/Password.Please try again.</span>
</div>
</form>`