search

Home  >  Q&A  >  body text

angular.js - How to verify that at least one of the multiple selection boxes is selected in angularjs?


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?

给我你的怀抱给我你的怀抱2815 days ago608

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-05-15 16:53:25

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

    reply
    0
  • 怪我咯

    怪我咯2017-05-15 16:53:25

    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.

    reply
    0
  • Cancelreply