GithubHelp home page GithubHelp logo

raymondcoplin / ngx-forms-builder Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 3.0 7.79 MB

A small library that adds validation with decorators and build angular forms. 🅰📝

Home Page: https://ngx-forms-builder-example.stackblitz.io/

TypeScript 73.27% JavaScript 13.96% CSS 1.43% HTML 11.34%
angular7 typescript forms builder angular-forms form-builder validator validators angular-validation angular-validators

ngx-forms-builder's Introduction

NGX Forms Builder

devDependencies Status npm      NPM

npm bundle size (minified + gzip) npm

A small library that adds validation with decorators and build angular forms 🅰📝

Demo

Try out our demo on Stackblitz!

Install

npm install ngx-forms-builder --save

Setup

You'll need to add NgxFormsBuilderModule to your application module. So that, the builder service will be accessible in your application.

@NgModule({
  declarations: [
    YourAppComponent
  ],
  imports: [
    NgxFormsBuilderModule.forRoot(),
    ...
  ],
  providers: [],
  bootstrap: [YourAppComponent]
})

export class YourAppComponent {}

Usage

import { Required, Email, Pattern, Min, Max, CustomValidator } from 'ngx-forms-builder';

export class Person {

  @Required()
  firstName: string;

  @Required()
  lastName: string;

  @Email()
  @Required()
  email: string;

  @Pattern(/^[.,_A-zÀ-ú0-9]*((-|\s)*[.,_A-zÀ-ú0-9])*$/)
  address: string;

  @Min(1)
  @Max(100)
  age: number;

  @Exclude()
  secretPassword: string;

  @CustomValidator(identificationValidator)
  documentNumber: string;

  constructor(firstName: string, lastName: string, email: string, age: number, address: string, secretPassword: string) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.email = email;
    this.age = age;
    this.address = address;
    this.secretPassword = secretPassword;
  }

}

/*-------------------------------------------------------------*/

import { Component, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { ModelFormBuilder } from 'ngx-forms-builder';
import { Person } from './person';
import { MatSnackBar } from '@angular/material/snack-bar';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  formGroup: FormGroup;

  constructor(private fb: ModelFormBuilder<Person>, private snackBar: MatSnackBar) { }

  ngOnInit() {
    const model = new Person('Raymond', 'Coplin', '[email protected]', 23, 'Wall Street, New York', '');
    this.formGroup = this.fb.build(model);
  }

  onSubmit() {
    this.snackBar.open(`${this.formGroup.get('firstName').value} ${this.formGroup.get('lastName').value}`, 'Saved', {
      duration: 2000,
    });
  }
}

ngx-forms-builder's People

Contributors

dannyfeliz avatar raymondcoplin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ngx-forms-builder's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.