Light weight reactive form error display package.
npm install reactive-form-validation-errorLight weight reactive form error display package.
This package will used to display the distinct error of your reactive forms control errors.
This will display both the default and custom errors,also you can customize the error messages of the default validators.
This project was generated with Angular CLI version 14.2.1.
``bash
npm install reactive-form-validation-error
`
version : 0.0.6 - Bug fixed
- if there is no custom error object it will not show any issues. there is no need to pass the custom error object
- Import ReactiveFormCustomValidationLibModule
- Place the `reactiveFormCustomValidation-error` selector where you wanted to show the validation error`
- Based on your form pass the respective @inputs` to the selector`
- If you are using the mat-form-field ` you have to place the selector inside the `mat-error` no need to specify anyother things`
- If you are not using mat-form-field` you have to customize the style of the error message.
import ReactiveFormCustomValidationLibModule in your root or shared modules.
`typescript
import {ReactiveFormCustomValidationLibModule} from 'reactive-form-validation-error'
@NgModule({
declarations: [],
imports: [ReactiveFormCustomValidationLibModule],
exports: [],
providers: [],
})
`
#In Html you can use the selector like below. In this selector type we have a diffrent type of inputs for the component.
Example.
#Form with no nested formgroup
`javascript
`
#Form with nested formgroup
`javascript
``
#Form with formArrayjavascript`
Type of @Inputs for component
`javascript`
@Input('form') form!: FormGroup;
@Input('controlName') formControlName!: string;
@Input('groupName') formGroupName: string = '';
@Input('arrayName') formArrayName: string = '';
@Input('groupIndex') groupIndex!: number;
@Input ('customDefaultErrorMsg') customErrorMsgObj! : DefaultValidationErrorsModel;
Below mentioned are the error message for the custom validators like `email` `min-length` `etc..`
`javascript
export class ValidationErrorConstant {
static readonly REQUIRED = 'This field is required';
static readonly EMAIL = 'Please enter the valid email';
static readonly MIN = 'Value should be greater than';
static readonly MAX = 'Value should not be greater than';
static readonly MIN_LENGTH = 'Length should be greater than';
static readonly MAX_LENGTH = 'Length should not be greater than';
static readonly PATTERN = 'Invalid format/pattern';
}
`
You can able to customize the default validation error messages. For that you have to import this dataObject VO
`javascript `
import {DefaultValidationErrorsModel} from 'reactive-form-validation-error'
VO model
`javascript`
export interface DefaultValidationErrorsModel{
emailError?: string;
requiredError?: string;
minLengthError?: string;
maxLengthError?: string;
minError?: string;
maxError?: string;
patternError?: string;
}
set the object in your model. the fields are optional
`javascript`
customErrorMsg : DefaultValidationErrorsModel = {
requiredError : "sample custom error"
}
then pass it to selector like below
`javascript``
Please make sure to update tests as appropriate.