1.0.0 • Published 4 years ago

ng-form-debounce-click v1.0.0

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

NgFormDebounceClick

  • A simple directive with no extenal dependencies.
  • Library location: projects/form-debounce-click directory of this repository.
  • works for Angular 8 and above in all devices.

Examples/Demo

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

@Inputs()

InputTypeRequiredDescription
validateFormFormGroupoptionalif validateForm is invalid the click event will be blocked
markFormAsTouchedbooleanOptional, default: trueif markFormAsTouched is true, All the controls in validateForm will be marked as touched on click.
debounceTimenumberOptional, default: 300only one click will be emitted even mutliple click events happened in the given debounceTime

@Outputs()

OutputTypeRequiredDescription
ngFormDebounceSubmitvoid>YESemits a debounce click event after checking the validateForm validity if exists
ngFormInvalidvoid>YESemits a event on click if the validateForm is invalid

Usage

1) Register the NgFormDebounceClickModule in your app module. > import { NgFormDebounceClickModule } from 'ng-form-debounce-click'

import { AppComponent } from './app.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { NgFormDebounceClickModule } from 'projects/ng-form-debounce-click';


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

2) Use the directive (NgFormDebounceClickDirective) in your component.

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

@Component({
  selector: 'app-root',
  template: `
  <div class="container">
  <div class="form" [formGroup]="formGroup">
    <label for="name"><b>Name</b></label>
    <input type="text" formControlName="Name">
    <p class="error" *ngIf="formGroup.controls.Name?.errors?.required && formGroup.controls.Name?.touched">Name is required</p>
  
    <label for="ssn"><b>SSN</b></label>
    <input type="text"  formControlName="SSN">
    <p class="error" *ngIf="formGroup.controls.SSN?.errors?.required && formGroup.controls.SSN?.touched">SSN is required</p>
      
    <button ngFormDebounceClick [validateForm]="formGroup" (ngFormDebounceSubmit)="submit()">Submit</button>
  </div>
</div>
`,
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

}

Running the example in local env

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