This is the archived documentation for Angular v5. Please visit angular.io to see documentation for the current version of Angular.

CheckboxRequiredValidator

npm Package @angular/forms
Module import { CheckboxRequiredValidator } from '@angular/forms';
Source forms/src/directives/validators.ts

Overview

      
      @Directive({
    selector: 'input[type=checkbox][required][formControlName],input[type=checkbox][required][formControl],input[type=checkbox][required][ngModel]',
    providers: [CHECKBOX_REQUIRED_VALIDATOR],
    host: { '[attr.required]': 'required ? "" : null' }
})
class CheckboxRequiredValidator extends RequiredValidator {
  validate(c: AbstractControl): ValidationErrors | null
  // inherited from forms/RequiredValidator
  required: boolean | string
  validate(c: AbstractControl): ValidationErrors | null
  registerOnValidatorChange(fn: () => void): void
}
    

Selectors

      
      input[type=checkbox][required][formControlName]
input[type=checkbox][required][formControl]
input[type=checkbox][required][ngModel]
    

Description

A Directive that adds the required validator to checkbox controls marked with the required attribute, via the NG_VALIDATORS binding.

Example

      
      <input type="checkbox" name="active" ngModel required>
    

Members

      
      validate(c: AbstractControl): ValidationErrors | null