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

@enzedd/form-control-validation

v1.2.0

Published

A simple directive to display angular form validation errors

Downloads

57

Readme

FormControlValidation

A simple directive to display angular form validation errors.

npm version Gitlab pipeline status coverage report

<input type="text" formControlName="lastName" nzFormControlValidation>

form-control-validation

  • No messy HTML markup is required for field errors; instead, one directive is enough
  • Humanized messages for built-in angular validators
  • Globally customizable error messages for builtin and user validators
  • Per control customizable error messages
  • Custom component can be provided to render validation errors

Examples/Demo

  • Demo
  • A simple example can be found under src/app directory of this repository.

Getting started

Step 1: Install form-control-validation:

npm

npm install --save @enzedd/form-control-validation

yarn

yarn add @enzedd/form-control-validation

Step 2: Import FormControlValidationModule and angular ReactiveFormsModule modules:

import {ReactiveFormsModule} from '@angular/forms';
import {FormControlValidationModule} from '@enzedd/form-control-validation';

@NgModule({
  declarations: [AppComponent],
  imports: [
    ...
    ReactiveFormsModule,
    FormControlValidationModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

Step 3: Add nzFormControlValidation directive to form control (input)

<form [formGroup]="form">
    <input type="text" formControlName="firstName" nzFormControlValidation>
</form>

Add validators to your form controls

Step 4 (Optional): Configuration

You can also set error messages by providing custom factory for FORM_CONTROL_ERRORS service.

import {FORM_CONTROL_ERRORS, FormControlErrors} from '@enzedd/form-control-validation';

export function formControlErrorsFactory(): FormControlErrors {
  const _formErrors = {
    ...
    minlength: ({requiredLength, actualLength}) => `Expected length is at least ${requiredLength}`,
  };
  return _formErrors;
}

@NgModule({
  ...
  providers: [
    {provide: FORM_CONTROL_ERRORS, useFactory: formControlErrorsFactory}
  ],
}

API

Inputs

| Input | Type | Default | Required | Description | | ------------- | ------------- | ------------- | ------------- | ------------- | | [nzFormControlValidation] | IFormControlValidationComponent | FormControlValidationComponent | yes (value not required) | Custom component can be provided to render formControl humanized validation error | [minError] | string | null | no | Error message for Validators.min1 | | [maxError] | string | null | no | Error message for Validators.max1 | | [requiredError] | string | null | no | Error message for Validators.required1 | | [requiredTrueError] | string | null | no | Error message for Validators.requiredTrue1 | | [emailError] | string | null | no | Error message for Validators.email1 | | [minlengthError] | string | null | no | Error message for Validators.minlength1 | | [maxlengthError] | string | null | no | Error message for Validators.maxlength1 | | [patternError] | string | null | no | Error message for Validators.pattern1 | | [validatorErrors] | Object | null | no | Error messages for other validators. Has lower priority than more specific error messages and can be overwritten by them |

1 If error message not specified, message from global configuration is used. See configuration section.

Development

Library location is under projects/form-control-validation directory of this repository.

Demo application is under src directory of this repository.

Development server

Run npm run lib:watch to incrementally build library as a background process in your dev environment

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Build library

Run npm run lib:build to build the project. The build artifacts will be stored in the dist/ directory.

Publishing

After building your library, go to the dist folder cd dist/form-control-validation and run npm publish.

Running unit tests

Run npm run lib:test to execute the library unit tests via Karma.