Gathering detailed insights and metrics for ngx-reactive-form-class-validator
Gathering detailed insights and metrics for ngx-reactive-form-class-validator
Gathering detailed insights and metrics for ngx-reactive-form-class-validator
Gathering detailed insights and metrics for ngx-reactive-form-class-validator
npm install ngx-reactive-form-class-validator
Typescript
Module System
Node Version
NPM Version
TypeScript (90.42%)
JavaScript (6.3%)
HTML (3.16%)
CSS (0.13%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
24 Stars
94 Commits
5 Forks
2 Watchers
7 Branches
3 Contributors
Updated on Jun 06, 2025
Latest Version
2.0.0
Package Id
ngx-reactive-form-class-validator@2.0.0
Unpacked Size
64.01 kB
Size
13.14 kB
File Count
24
NPM Version
10.9.2
Node Version
22.16.0
Published on
Jun 06, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
4
A lightweight library for dynamically validate Angular reactive forms using class-validator library.
npm install --save ngx-reactive-form-class-validator
// OR
yarn add ngx-reactive-form-class-validator
"@angular/common": ">= 2.0.0 <= ^20.0.0",
"@angular/core": ">= 2.0.0 <= ^20.0.0",
"@angular/forms": ">= 2.0.0 <= ^20.0.0",
"class-validator": ">= 0.12.0 <= ^0.14.0"
Please note that properties without a class-validator decorator will not be validated, see class-validator profile.ts
import { IsEmail, IsNotEmpty, ValidateNested } from 'class-validator';
class Profile {
@IsNotEmpty()
public firstName: string;
@IsNotEmpty()
public lastName: string;
@IsEmail()
public email: string;
@ValidateNested()
public address: Address;
}
address.ts
import { IsNotEmpty, IsOptional, ValidateNested } from 'class-validator';
class Address {
@IsNotEmpty()
public street: string;
@IsNotEmpty()
public city: string;
@IsOptional()
public state: string;
@IsNotEmpty()
public zip: string;
}
Untyped version of ngx-class-validator form classes exist in order to be backward compatible with angular untyped form classes
As described here to be able to use the ClassValidatorFormBuilderService
, you need to import ClassValidatorFormBuilderModule.
app.module.ts
imports: [
...
ClassValidatorFormBuilderModule.forRoot(),
...
],
Then in your component profile-form.component.ts
public constructor(
private fb: ClassValidatorFormBuilderService,
) { }
profileForm = this.fb.group(Profile,
{
firstName: [''],
lastName: [''],
email: [''],
address: this.fb.group(Address,
{
street: [''],
city: [''],
state: [''],
zip: ['']
}
),
});
As it's possible with angular FormGroup
class we can directly create a ClassValidatorFormGroup
using the constructor
export class ProfileFormComponent {
profileForm = new ClassValidatorFormGroup({
firstName: new ClassValidatorFormControl(''),
lastName: new ClassValidatorFormControl(''),
});
}
Now, setting value to any of form controls, will perfom the validator set in the corresponding class.
this.profileForm.controls.email.setValue('notEmailValue');
console.log(this.profileForm.controls.email) // { isEmail: 'email must be an email' }
this.profileForm.controls.email.setValue('email@email.com');
console.log(this.profileForm.controls.email) // null
By default, ngx-reactive-form-class-validator
validates form controls after the form is fully initialized (ngAfterViewInit).
If you want validation to run immediately after form initialization (for example, in ngAfterViewInit or just after you create a FormGroup), you can enable eager validation at the ClassValidatorFormGroup/FormBuilder level.
import { ClassValidatorFormGroup, ClassValidatorFormControl } from 'ngx-reactive-form-class-validator';
const formGroup = new ClassValidatorFormGroup({
email: new ClassValidatorFormControl(''),
password: new ClassValidatorFormControl('')
}, null, { eagerValidation: true }); // 👈 Enable eager validation here
// Or using the form builder
public constructor(
private fb: ClassValidatorFormBuilderService,
) { }
profileForm = this.fb.group(
Profile,
{
firstName: [''],
lastName: [''],
email: [''],
address: this.fb.group(Address,
{
street: [''],
city: [''],
state: [''],
zip: ['']
}
),
},
undefined,
{ eagerValidation: true } // 👈 Enable eager validation here
);
It is possible as well to combine dynamic validation with custom validation. There are several ways to do it:
this.fb.group (Profile, {
email: ['', Validators.required],
...
}
)
// OR
new ClassValidatorFormGroup(Profile, {
email: new ClassValidatorFormControl('', Validators.required)
})
setValidators
/setValidatorsWithDynamicValidation
methodsBoth setValidators
and setValidatorsWithDynamicValidation
replace validators provided in parameter, the only one difference is that setValidatorsWithDynamicValidation
add given validators as well as re-enable dynamic validation, as the setValidators
method replace validators with given ones without re-enabling dynamic validation.
emailControl.setValidators(Validators.required); // there will be only Validators.required validator
emailControl.setValidatorsWithDynamicValidation(Validators.required) // there will be Validaros.required validator as well as dynamic validator
An Angular module that provides ClassValidatorFormBuilderService for dependency injection.
It can either be imported forRoot
or normally (We don't recommend importing it normally because that will create multiple instances of ClassValidatorFormBuilderService).
app.module.ts
imports: [
...
ClassValidatorFormBuilderModule.forRoot(),
...
],
An Angular injectable service having the same methods as Angular FormBuilder except a minor change of group
method signature, see below:
group(
classType: ClassType<any>, // The class type of the form group value.
// Angular FormBuilder group method parameters
controlsConfig: { [p: string]: any },
options?: AbstractControlOptions | { [p: string]: any } | null,
): ClassValidatorFormGroup;
We've introduced a new parameter called classType
(a class type containing class-validator decorators) that you should provide, to enable us to perform dynamic validations.
A typescript class extending angular FormGroup class, with a minor change of constructor
signature, the classType parameter.
export class ClassValidatorFormGroup extends FormGroup {
public constructor(
private readonly classType: ClassType<any>,
// Angular FormGroup constructor parameters
controls: {
[key: string]: AbstractControl;
},
validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null,
asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null,
) {
...
}
A typescript class extending angular FormControl class, that will use the classType instance to perform validations and assign validation errors to the ClassValidatorFormControl
.
As it extends angular FormControl class, it contains all FormControl
methods, with a custom new method:
setValidatorsWithDynamicValidation(newValidator: ValidatorFn | ValidatorFn[] | AbstractControlOptions | undefined): void
This method has the same signature as FormControl setValidators method. In addition it re-enables dynamic validation when disabled.
We are open for proposals, so please don't hesitate to create issues if you want to report any bugs/proposals/feature requests.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
9 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 9
Reason
Found 0/14 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
41 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More