1.4.1 • Published 9 months ago

ng-reactive-dynamic-form v1.4.1

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

NgReactiveDynamicForm

The Angular library simplifies the creation of reactive forms using JSON data. With a JSON object, developers can build forms with form controls, validations, and custom configurations efficiently. The library enables the creation of dynamic and interactive forms, saving time and enhancing code readability in Angular applications.

Installation

Install via NPM, using the command below.

npm install ng-reactive-dynamic-form

Compatibility

ng-reactive-dynamic-form is compatible with the following versions of Angular:

Angular 16.1.8 and later

Getting started

Import the NgReactiveDynamicFormModule in your root application module:

import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { NgReactiveDynamicFormModule } from 'ng-reactive-dynamic-form';

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

The Angular library allows easy creation of dynamic reactive forms by passing a JSON array to the component.

 <lib-ng-reactive-dynamic-form
    [formData]="form"
    [buttonData]="buttonData"
    (formSubmitted)="onSubmit($event)">
 </lib-ng-reactive-dynamic-form>
 export class AppComponent implements OnInit{
  public form: Array<FormDataModel | checkBoxFormDataModel> = [
    {
      fieldName: "checkbox", 
      formControl: "checkbox1", 
      errorMsg: "checkbox is required", 
      initalValue: true, 
      inputType: "checkbox", 
      parentLabel : "",
      customInputClass: "checkbox",
      customLabelClass: "checkbox_label",
      id: "checkbox_label",
      validation: true
    },
    {
      fieldName: "Name", 
      formControl: "Name", 
      errorMsg: "Name is required", 
      initalValue: "Yo", 
      inputType: "text",
      placeholder: "Enter name",
      customInputClass: "input_name_form_control",
      customLabelClass: "checkbox_label",
      id: "checkbox_label",
      validation: true, 
      characterValidation: {
        requried: true,
        minLength: 3,
        maxLength: 10
      }
    },
    {
      fieldName: "number", 
      formControl: "number", 
      errorMsg: "number is required", 
      initalValue: 20, 
      inputType: "number",
      placeholder: "Enter number",
      customInputClass: "input_number_form_control",
      customLabelClass: "checkbox_label",
      id: "checkbox_label",
      validation: true,
      characterValidation: {
        requried: true,
        minLength: 3,
        maxLength: 10
      }
    },
    {
      fieldName: "password", 
      formControl: "password", 
      errorMsg: "Password is required", 
      initalValue: "So", 
      inputType: "password",
      placeholder: "Enter password",
      customInputClass: "input_password_form_control",
      customLabelClass: "checkbox_label",
      id: "checkbox_label",
      validation: true, 
      characterValidation: {
        requried: true,
        minLength: 3,
        maxLength: 10
      }
    },
  ];
}

To get all the input data entered by the user from the form, you can use the #formValue object in the onSubmit function

  onSubmit(formValue: any){
    console.log('formValue', formValue)
  }

The primary button is a submit type button, and the secondary button is a reset button. You can customize the button names and their classes according to your requirements

  public buttonData = {
    primaryButton: {
      buttonName: "Submit",
      class: "submit-btn"
    },
    resetButon: {
      buttonName: "Reset",
      isVisible: true,
      class: "reset-btn"
    }
  }

Default Locale Options

KeyValue
fieldNameInput field name
formControlReactive form's form control (input)
errorMsgError message
initalValueInitial value of the form control (input)
inputTypeInput type: text, checkbox, password, number
placeholderPlaceholder of the form control (input)
customInputClassCustomized class for form control (input)
customLabelClassCustomized class for form control's label
idID of the form control (input)
validationBoolean (true or false)
primaryButton.buttonNamePrimary button name
primaryButton.buttonNamePrimary button name
primaryButton.classPrimary button customized class
resetButon.buttonNameReset button name
resetButon.classReset button customized class
resetButon.isVisibleProperty determines whether the button should be displayed or hidden

License

MIT License

1.4.1

9 months ago

1.4.0

9 months ago

1.3.4

9 months ago

1.3.3

9 months ago

1.3.2

9 months ago

1.3.1

9 months ago

1.3.0

9 months ago

1.2.1

9 months ago

1.2.0

9 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.0

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

0.0.1

9 months ago