Angular 7+ Validator, a library handle validation messages easy and automatic
Branch: master
Clone or download

README.md

ngx-validator Build Status

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.

Demo

Live Demo

Use Case

Installation

npm install @why520crazy/ngx-validator --save
# or
yarn add @why520crazy/ngx-validator

Usage

Loading the module in the app module

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 directives to form elements

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>

Development

$ git clone git@github.com:why520crazy/ngx-validator.git
$ cd ngx-validator
$ npm install
$ npm run start
$ npm run test

Building & Publish

$ npm run build
$ npm run publish

Links

Angular.io

Angular.cn

Worktile.com

License

MIT License