npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reactive-form-validation-error

v0.0.6

Published

Light weight reactive form error display package.

Downloads

10

Readme

Reactive Form Custom Validation Errors

Light 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.

Installation

npm install reactive-form-validation-error

Whats new !!

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

Steps

  • 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.

Usage

import ReactiveFormCustomValidationLibModule in your root or shared modules.


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

<reactiveFormCustomValidation-error [form]="loginForm" [controlName]="'email'" >
</reactiveFormCustomValidation-error>

#Form with nested formgroup

<reactiveFormCustomValidation-error [form]="sampleForm" [controlName]="'sampleFormControlName'" 
[groupName] = "'sampleGroupName'" > </reactiveFormCustomValidation-error>

#Form with formArray

<reactiveFormCustomValidation-error [form]="sampleForm" [controlName]="'sampleFormControlName'" 
[groupName] = "'sampleGroupName'" [arrayName] = "'sampleFormArrayName'" [groupIndex] = "sampleIndex" > 
</reactiveFormCustomValidation-error>

Type of @Inputs for component

  @Input('form') form!: FormGroup;
  @Input('controlName') formControlName!: string;
  @Input('groupName') formGroupName: string = '';
  @Input('arrayName') formArrayName: string = '';
  @Input('groupIndex') groupIndex!: number;
  @Input ('customDefaultErrorMsg') customErrorMsgObj! : DefaultValidationErrorsModel;

Custom default validation errors

Below mentioned are the error message for the custom validators like email min-length etc..

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

import {DefaultValidationErrorsModel} from 'reactive-form-validation-error'

VO model

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

customErrorMsg : DefaultValidationErrorsModel = {
    requiredError : "sample custom error"
   }

then pass it to selector like below

<reactiveFormCustomValidation-error [form]="loginForm" [controlName]="'email'" [customDefaultErrorMsg] = "customErrorMsg" >
</reactiveFormCustomValidation-error>

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Authors

Arun Kumar Ravindran

License

MIT