我最近开始在AngularJS工作。我试图将单选按钮验证为: -
<input type="radio" ng-model="CustGender" name="uCustGender" value="Male" required /> Male
<input type="radio" ng-model="CustGender" name="uCustGender" value="Female" required /> Female
<span class="error" ng-show="(f1.uCustGender.$dirty || submitted) && f1.uCustGender.$error.required">Gender required!</span>
<input id="Submit1" type="submit" value="Submit" class="btn btn-success" />
但它没有在Button Click上验证。我正在寻找解决方案并遇到了Using Angular to validate radio button choice的一些链接,但他们似乎采用了不同的方法。 请帮助。
答案 0 :(得分:0)
您需要在{span}假设&#39; f1&#39;是表格名称。
f1.$submitted
答案 1 :(得分:0)
我希望您已将它们包含在表单标记中,并在表单中提及novalidate属性,如下所示:
<form name="f1" ng-submit="submitTeamMember($event)" novalidate class="form-horizontal" enctype="multipart/form-data" method="post" ng-controller="userFormModalCtrl">
<input type="radio" ng-model="CustGender" name="uCustGender" value="Male" required /> Male
<input type="radio" ng-model="CustGender" name="uCustGender" value="Female" required /> Female
<span class="error" ng-show="(f1.uCustGender.$dirty || submitted) && f1.uCustGender.$error.required">Gender required!</span>
<input id="Submit1" type="submit" value="Submit" class="btn btn-success" />
</form>