angular.js - How to verify that at least one of the multiple selection boxes is selected in angularjs?
给我你的怀抱
给我你的怀抱 2017-05-15 16:51:25
0
2
605

angularjs provides basic form verification, such as attributes such as ng-minlength, and then you can use form.inputname.$valid to determine whether the verification has passed

But how to verify a multi-select box like checkbox? To verify that at least one is selected, is there any built-in method? I feel like it shouldn’t be too complicated to write, right?

给我你的怀抱
给我你的怀抱

reply all(2)
漂亮男人

I came up with the method myself, see the blog: angularjs form verification checkbox

刘奇
html<input type="checkbox" ng-model="form.cb1" ng-required="form.cb1 || form.cb2 || form.cb3">
<input type="checkbox" ng-model="form.cb2" ng-required="form.cb1 || form.cb2 || form.cb3">
<input type="checkbox" ng-model="form.cb3" ng-required="form.cb1 || form.cb2 || form.cb3">
If the judgment expression of

ngRequired is too long, just bind a function to return boolean.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template