1.0.0 • Published 7 years ago

semantica-dynamic-form-generator v1.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

Angular Form Generator

Version Version Version A dynamic form generator for Angular with material design Example

Installation

//TODO

npm install @angular/material
npm install angular-form-generator

Setup

Import the FormGenerator Module and add it to the 'imports' of your module

import { FormGeneratorModule } from 'angular-form-generator';

@NgModule({
  imports: [FormGeneratorModule],
  ...
})
export YourModule { }

Set a link to a material theme in the <head> tag of index.html at the root of your application

<link href="node_modules/@angular/material/prebuilt-themes/indigo-pink.css" rel="stylesheet">

Form Configuration

The form configuration is a json object that consists of required and optional parameters.

{
  "formId": '123456Test',
  "form": 'animals',
  "type": 'lion',
  "version": 'v1',
  "pages":[
    {
      "title": "Title",
      "groups": [
        {
          "orientation": 0,
          "fields": [
            {
              "fieldName": 'field',
              "type": 'text'
            }
          ]
        }
      ]
    }
  ]
}

The full form configuration documentation.

Usage

Create a new formConfig object. This will set all the required parameters to their default.

let formConfig = new FormConfig(formConfigJson);

Insert the <ngdg-form> inside your components html.

<div *ngFor="let pageObject of formConfig.pages">
  <ngdg-form [page]="pageObject" ... ></ngdg-form>
</div>

Form component

The inputs and outputs.

ParameterTypeDescriptionKind
pagePageInsert a page object the form generator has to buildInputRequired
dataanyInsert an object with the already filled in data. Make sure that the fieldName in the formConfig follow the path in the data object. ExampleInputOptional
lovArray key value pairIf the form has dropdowns that contain standard lovsInputOptional
readonlybooleanSet if the whole form is readonly or not. Default: falseInputOptional
focusChangedEventEmitterEmits an event wheter a form control is focused or bluredOutputOptional
registerFormEventEmiiterEmits an event when a new form is build. Returns a FormGroupOutputOptional
nextEventEmitterEmits an event when a button with type button is clickedOutputOptional
submitEventEmitterEmits an event when a button with type submit is clickedOutputOptional

Data example

A data object example:

{
  information: {
    firstName: "Donald",
    lastName: "Duck"
  },
  answers: {
    age: 10,
    height: "1.80 m"
  }
}

A compatible formConfig object:

{
  "formId": '123456Test',
  "form": 'animals',
  "type": 'lion',
  "version": 'v1',
  "pages":[
    {
      "title": "Title",
      "groups": [
        {
          "orientation": 0,
          "fields": [
            {
              "fieldName": 'answers.age',
              "type": 'number'
            },
            {
              "fieldName": 'answers.height',
              "type": 'text'
            }
          ]
        }
      ]
    }
  ]
}