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

@ahmedtamseer/tn-form-error

v1.0.4

Published

Angular package for validating both reactive and template driven forms

Downloads

9

Readme

TnFormError

The Angular library for Form Validation.

ng add @ahmedtamseer/tn-form-error

What is TnFormError?

TnFormError is angular package for validating both reactive and template driven forms.

Quickstart

1. Create a new project

npm install -g @angular/cli
ng new <project-name>
cd <project-name>

The Angular CLI's new command will set up the latest Angular build in a new project structure.

2. Install Angular Form Error

ng add @ahmedtamseer/tn-form-error

Now that you have a new project setup, install Angular Form Error from npm.

3. Setup @NgModule for the TnFormErrorModule

Open /src/app/app.module.ts, inject the TnFormErrorModule.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { TnFormErrorModule } from '@ahmedtamseer/tn-form-error';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ReactiveFormsModule,
    FormsModule,
    TnFormErrorModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

4. Use it in your component

import { Component } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';

@Component({
  selector: 'app-root',
  template: `
  <form [formGroup]="demoForm">
    <div>
        <label for="name">Name</label>
        <input type="text" formControlName="name" name="name" placeholder="Name validator">
        <tn-form-error [control]="demoForm.controls.name" [field]="'Name'"></tn-form-error>
    </div>
  </form>
  `
})
export class MyApp {

  demoForm: FormGroup;

  constructor() {
      this.demoForm = new FormGroup({
      name: new FormControl('', [Validators.required])
    });
  }
}

5. Use TnFormErrorService service for validation

import { Component } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';

import { TnFormErrorService } from '@ahmedtamseer/tn-form-error';

@Component({
  selector: 'app-root',
  template: `
  <form [formGroup]="demoForm">
    <div>
        <label for="name">Name</label>
        <input type="text" formControlName="name" name="name" placeholder="Name validator">
        <tn-form-error [control]="demoForm.controls.name" [field]="'Name'"></tn-form-error>
    </div>
  </form>
  `
})
export class MyApp {

  demoForm: FormGroup;

  constructor(
      private tnFormErrorService: TnFormErrorService
  ) {
      this.demoForm = new FormGroup({
      name: new FormControl('', [this.tnFormErrorService.nameValidator])
    });
  }
}

6. Run your app locally

ng serve

Resources

Stackblitz Template - A demo app which shows how to use package for Reactive and Template Driven form.

Developer Guide

<tn-form-error [control]="formControl|ngModel">

| attribute | purpose | | ---------|--------------------| | [control] | Formcontrol or a ngModel. Required | | [field] | String. Default value is 'Field'. Ex:- if you pass [field]="'Name'" error message will be Name is required else Field is required | | [class] | String. List of classes separated by space. By default is displayed in red color. Ex:- [class]="'bg-danger text-white'" | | [msg] | String. Default is package generated message. You can display custom message. Ex:- [msg]="This is custom message" |

TnFormErrorService

| method | purpose | | ---------|--------------------| | .emailValidator | To validate email. Email should have min of 5 characters | | .nameValidator | To validate name. Name should contain atleast 2 characters and should not contain any special character other than a space | | .numberValidator | To validate interge number. Number should contain numbers | | .usMobileValidator | To validate US mobile number. Ex:- (123) 123 1234, (123) 123-1234 or 1231231234 | | .inMobileValidator | To validate IN mobile number. Ex:- (91) 9841-11-11-11, (91) 9841111111, 9841-11-11-11, 9841-111111, 9841 11 11 11 or 9841111111 | | .yearValidator | To validate year. Ex:- 1900 or 2100 | | .fullDateValidator | To validate full date dd mm yyyy. Ex:- 20 10 1900 or 20-9-1900 | | .passwordValidator | To validate Password. Password should contain min of 8 character, must have atleast one uppercase letter, one lowercase letter, one number and one special character. Ex:- exampleTn@1_2 |