1

How to validate this checkboxes, at least one must be checked, if not, there has to be some message or alert

<div class="form-group" ng-class="{ 'has-error' : actionsAddForm.active.$invalid && !actionsAddForm.active.$pristine }">
    <label class="control-label col-sm-2">Days*</label>
    <div class="col-sm-10">
        <label>Monday
          <input type="checkbox" ng-model="actions.value1">
        </label>
        <label>Tuesday
          <input type="checkbox" ng-model="actions.value2">
        </label>
        <label>Wednesday
          <input type="checkbox" ng-model="actions.value3">
        </label>
        <label>Thursday
          <input type="checkbox" ng-model="actions.value4">
        </label>
        <label>Friday
          <input type="checkbox" ng-model="actions.value5">
        </label>
        <label>Saturday
          <input type="checkbox" ng-model="actions.value6">
        </label>
        <label>Sunday
          <input type="checkbox" ng-model="actions.value7">
        </label>
    </div>

1 Answer 1

1

This can be done :

<div ng-hide="actions.value1 || actions.value2 || actions.value3...">
    You have an error 
</div>

Otherwise, if you want to be able to use $valid,... You will have to create a custom directive inheriting from ngModelController, and adding your custom validators inside : https://docs.angularjs.org/api/ng/type/ngModel.NgModelController

Sign up to request clarification or add additional context in comments.

1 Comment

ok, that is most basic and working solution, thx, for now ill leave it like that, and start playing with custom directives

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.