A super flexible and time saving Validation logic handeling directive for Angular Reactive forms.
npm install ngx-form-validator-superA super flexible and time saving Validation logic handeling directive for Angular Reactive forms.
typescript
...
import { NgxFormValidatorModule, NgxValidatorLabelService } from "ngx-form-validator-super";
@NgModule({
declarations: [
AppComponent
],
imports: [
...
// 1. Import in app module
NgxFormValidatorModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { // 2. Add validation messages using NgxValidatorLabelService service (you can inject this service in any component)
labelService.setValidationMsg(
{
required :"It is a required field. please fill some value",
range:"value must be in range"
}
)
}
``
html
`
Note : To Show error properly always enclose control inside any conatiner element like div.
AppComponent.ts
`typescript
import { Component } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
Form= new FormGroup({
test:new FormControl(null,Validators.required)
})
}
`
Styles and theme
`css
@import "ngx-form-validator-super/src/styless.css";
``* setValidationMsg(labelObject) : This function is used to set the validation messages. It accept a parameter which is label objects.
* appendValidationMsg(labelObject) : This function is used to append additional validation messages to the existing object.Duplicate are overridden. It accept a parameter which is label objects.
* clearValidationMsg() : This function is used to clear validation messages.
label objects : A js object contaning key value (as string) pair ex- { required :"This field is required" }