0.0.4 • Published 6 years ago

ngx-form-validation v0.0.4

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

ngx-form-validation

angular 2 and beyond json powered form validation library

  • Exposes a provider that receives an uri( that return a json form) and returns a complete validated FormGroup
  • Exposes a provider that receives a json form and returns a complete validated formGroup

Installation

Install ngx-form-validation from npm:

npm install ngx-form-validation --save

Setup

Set up in your project like this

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';


import { AppComponent } from './app.component';
import {FormValidationModule} from "ngx-form-validation";
import {ReactiveFormsModule} from "@angular/forms";
import {HttpClientModule} from "@angular/common/http";


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    ReactiveFormsModule,
    BrowserModule,
    FormValidationModule,
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  • ReactiveFormsModule and HttpClientModule are mandatory

Then you import FormValidationService in your component

import {FormValidationService} from "ngx-form-validation/lib/service/form-validation.service";
.
.
.
constructor(private formValidationService: FormValidationService) {}

The following APIs are provided :

FunctionUsage
toFormGroupGets the form validation object as a param and returns a complete instance of FormGroup
createFormGets the form object from the endpoint (specified by the provided uri) and generates acomplete FormGroup
getValidationObjectGets the form object from the endpoint (specified by the provided uri)

Here's an example of json powered form

 let form: any = [
    {
      key: "firstName", value: "khaled", "type": "textarea", validations: {
      required: true,
      minLength: "7",
      maxLength: "8",
      pattern: "",
      custom: "",
      email:false
    }
    },
    {
      key: "psw", value: "", "type": "password", validations: {
      required: true,
      minLength: "7",
      maxLength: "15",
      pattern: "",
      custom: "",
      email:false
    }
    }
  ];

##Here you can find a fully working example