ngx-group-validator
v0.1.0
Published
Angular FormGroup conditional validators
Downloads
3
Readme
NgxGroupValidator
Angular 8+ conditional validation rules for FormGroup
Demo available here
Example
this.form = this.fb.group({
checkbox: [false],
comment: ['']
}, {
validators: NgxGroupValidators.sync({
comment: [
{
condition: {
paths: ['checkbox'],
check: (a) => a.value === true
},
validators: Validators.required
}
]
})
});
How it works
Validate comment
control than, and only then, when described in condition
part check
function will return true
. And comment
control will be validated with validators
part
of configuration.
Realize that the every control in configuration can have many conditions.
And each condition has own check
function, and each condition validate control with it's
own validation rules.
Instalation
npm install ngx-group-validator
yarn add ngx-group-validator