0.2.0 • Published 6 years ago

ng4-form-fields v0.2.0

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

Angular 4 dynamic form field builder

Based on https://github.com/toddmotto/angular-dynamic-forms by Todd Motto.

Setup your form in your component and keep control of your input fields with this library.

Getting Started

npm install ng4-form-fields

Prerequisites

This package is for use with Angular Reactive forms only.

Installing

After downloading add the components module to your app module.

import {FormFieldsModule} from 'ng4-form-fields/form-fields.module'

@NgModule({
  imports: [
    FormFieldsModule,
    ReactiveFormsModule // You must use Reactive Forms
  ]
})

Import the interface in your component.

import { FormFieldsConfig } from 'ng4-form-fields/models/form-fields-config';

In your component with the form add a property for all the elements in your form you wish to load dynamic with this library. Here is an example for a number input field.

config: FormFieldsConfig[] = [
    {
      element: 'input',
      type: 'number',
      label: 'First name',
      name: 'number',
      min: '10',
      max: '50',
      step: '5',
      placeholder: 'Enter your name',
      validation: [Validators.required, Validators.minLength(4)]
    }
]

Note: I hope to make a small list of various properties you can use, but they are in the FormsFieldsConfig interface.

In your template you can place this code to create all the configured form fields.

    <form [formGroup]="testForm">
    <!-- This is the directive for the module -->
      <ff-inputs 
        *ngFor="let field of config;"
        [config]="field"
        [group]="testForm"
        >
      </ff-inputs>
    <!-- The form you must build yourself. -->
    </form>

Running the tests

No test written

Versioning

We use SemVer for versioning.

Authors

  • Jörgen de Groot - Initial work - Shift"o

License

This project is licensed under the ICS License. This project is my first NPM module, no support guaranteed

Acknowledgments

  • Todd Moto, thanks for your help on dynamic components in Angular
0.2.0

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago