1.0.2 • Published 4 years ago

angular-weblineindia-email v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

AngularJS - Email Input Component with Validation

AngularJS based Email component, provides option to add single / multiple email input field with validation. The email value is automatically validated on blur event. You can change validation message using props. You can also disable email field using disable props.

Table of contents

Browser Support

ChromeFirefoxSafariEdgeIE
83.0 ✔77.0 ✔13.1.1 ✔83.0 ✔11.9 ✔

Demo

npm.io

Getting started

Install the npm package:

npm install angular-weblineindia-email
#OR
yarn add angular-weblineindia-email

Usage

Use the <angular-weblineindia-email> component:

Add in app.module.ts file

import { NgModule } from "@angular/core";
import { EmailModule } from "angular-weblineindia-email";

@NgModule({
  imports: [EmailModule]
})
export class AppModule {}

Add in app.component.ts file

import { faPlus, faMinus } from "@fortawesome/free-solid-svg-icons";

export class AppComponent {
  faPlus: any = faPlus;
  faMinus: any = faMinus;

  values: any = [{ email: "" }];

  emailValue: any = {
    placeholder: "Enter Email",
    maxlength: 50,
    emailFormateError: "Email is not valid",
    duplicateEmailError: "Do not enter same email",
    name: "email",
    id: "email",
    disabled: false,
    value: "",
    isMultiple: true,
    isShowPlus: true,
    tabindex: 0,
    index: 0
  };

  onFocus(event) {
    event.target.placeholder = "";
  }

  onBlur(event) {
    event.target.placeholder = this.emailValue.placeholder;
  }

  onChange(data) {
    this.values[data.index].email = data.event.target.value;
  }

  onAddMultipleEmail() {
    this.values.push({ email: "" });
  }
}

Add in app.component.html file

<div *ngFor="let value of values;let indexOfelement=index;">
  <lib-email
    [placeholder]="emailValue.placeholder"
    [maxlength]="emailValue.maxlength"
    [emailFormateError]="emailValue.emailFormateError"
    [duplicateEmailError]="emailValue.duplicateEmailError"
    [name]="emailValue.name"
    [id]="emailValue.id"
    [disabled]="emailValue.disabled"
    [value]="value.email"
    [isMultiple]="emailValue.isMultiple"
    [isShowPlus]="values.length-1 === indexOfelement"
    [tabindex]="emailValue.tabindex"
    [index]="indexOfelement"
    [emailArray]="values"
    (focus)="onFocus($event)"
    (blur)="onBlur($event)"
    (change)="onChange($event)"
    (onPlus)="onAddMultipleEmail()"
  ></lib-email>
</div>

Available Props

PropTypedefaultDescription
maxlengthNumber50maxlength for email
idStringemail id
emailFormateErrorStringEmail is not validemail formate validation
duplicateEmailErrorStringDo not enter same emailduplicate email error
onMultipleEmailFunctionwhen click on plus icon on email
nameStringemailemail name.
indexNumber0email index.
emailArrayArrayObject{email : ''}email default array
isMultipleBooleantrueflag to implement multiple email
isShowPlusBooleanfalseflag to show plus icon for add multiple email
placeholderStringEmailemail placeholder
disabledBooleanfalsedisable input field
tabindexNumber0email tabIndex
valueStringemail value

Methods

NameDescription
focusGets triggered when the input field receives focus.
blurGets triggered when the input field loses focus.
changeGets triggered every time when input got changed.
onPlusGets triggered every time when click on plus button.

Want to Contribute?

  • Created something awesome, made this code better, added some functionality, or whatever (this is the hardest part).
  • Fork it.
  • Create new branch to contribute your changes.
  • Commit all your changes to your branch.
  • Submit a pull request.

Collection of Components

We have built many other components and free resources for software development in various programming languages. Kindly click here to view our Free Resources for Software Development


Changelog

Detailed changes for each release are documented in CHANGELOG.md.

License

MIT

Keywords

angular-weblineindia-email, email-validation-component, email-input, angularjs-email-input, multi-email-input