An Angular7+ form validator library
handle validation messages easy and automatic, don't need to manually write error tips templates, just configure validation rules, and support extensive custom feedback strategy.
npm install @why520crazy/ngx-validator --save
# or
yarn add @why520crazy/ngx-validator
import { NgxValidatorModule, ValidationFeedbackStrategyBuilder } from '@why520crazy/ngx-validator';
@NgModule({
imports: [
CommonModule,
NgxValidatorModule.forRoot({
validationFeedbackStrategy: ValidationFeedbackStrategyBuilder.bootstrap(), // default is bootstrap 4 style
validationMessages: {
username: {
required: 'Username is required.',
pattern: 'Incorrect username format.'
}
}
})
]
})
class AppModule {}
add ngxFormValidator
directive to form element and add ngxFormSubmit
directive to submit button.
<form name="exampleForm" novalidate [ngxFormValidator]="validatorConfig">
<div class="form-group">
<label for="email1">Email address</label>
<input type="email" email class="form-control" name="email" id="email1"
[(ngModel)]="model.email" required placeholder="Enter email" />
</div>
<button type="button" (ngxFormSubmit)="submit()" class="btn btn-primary">Submit</button>
<form>
$ git clone git@github.com:why520crazy/ngx-validator.git
$ cd ngx-validator
$ npm install
$ npm run start
$ npm run test
$ npm run build
$ npm run publish