【发布时间】:2014-12-15 08:03:39
【问题描述】:
我正在为我的应用程序使用 ionic/angularjs 制作表单。在那里,我对所有字段都使用了验证。但是我对单选按钮的验证无法正常工作。如果未选择单选按钮(应该这样),它会显示错误消息,但即使我选择了单选按钮,它也会显示错误消息。我该如何解决这个问题?
或者如何设置默认选中的单选按钮?
我的表格
<div class="form-group" ng-class="{ 'has-error' : (userForm.choice.$invalid || userForm.choice.$pristine) && submitted }">
<label class="labelColor"><h5><b>Select Standing Order Type</b></h5></label>
<ion-radio ng-model="choice" name="choice" id="choice" ng-value="'A'">Utility Standing Order</ion-radio>
<ion-radio ng-model="choice" name="choice" id="choice" ng-value="'B'">Own Account Standing Order</ion-radio>
<ion-radio ng-model="choice" name="choice" id="choice" ng-value="'C'">Third Party Fund Transfer Standing Order</ion-radio>
<span class="help-inline" ng-show="(userForm.choice.$pristine && submitted) ||( userForm.choice.$error.required && submitted)" >Standing Order Type Should Be Selected.</span>
</div>
<!-- BUTTONS -->
<div class="col"style="text-align: center">
<button align="left" class="button button-block button-reset" style="display: inline-block;width:100px;text-align:center " type="reset"
ng-click="submitted = false; reset()" padding-top="true">Reset</button>
<button class="button button-block button-positive" style="display: inline-block;width:100px "
ng-click="submitted=true; "padding-top="true">Proceed</button>
</div>
</form>
</ion-content>
</ion-view>
【问题讨论】:
-
我会要求您: 1 - 简化您的 HTML 代码(我们不需要知道所有细节,例如 CSS ID 或类); 2 - 向我们展示 JavaScript; 3 - 将其发布在 plnkr 或 JSFiddle 中
-
我的验证部分完全在 html 中完成
-
如果可以的话,请看#1。
标签: html angularjs validation ionic-framework