npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

angular-form-generator

v1.1.4

Published

A dynamic form generator for angular with material design

Readme

Angular Form Generator

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

Installation

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, MdNativeDateModule],
  ...
})
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.

| Parameter | Type | Description | Kind | | |---|---|---|---|---| | page | Page | Insert a page object the form generator has to build | Input | Required | | data | any | Insert an object with the already filled in data. Make sure that the fieldName in the formConfig follow the path in the data object. Example | Input | Optional | | lov | Array key value pair | If the form has dropdowns that contain standard lovs | Input | Optional | | readonly | boolean | Set if the whole form is readonly or not. Default: false | Input | Optional | | focusChanged | EventEmitter | Emits an event wheter a form control is focused or blured | Output | Optional | | registerForm | EventEmiiter | Emits an event when a new form is build. Returns a FormGroup | Output | Optional | | next | EventEmitter | Emits an event when a button with type button is clicked | Output | Optional | | submit | EventEmitter | Emits an event when a button with type submit is clicked | Output | Optional |

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'
            }
          ]
        }
      ]
    }
  ]
}

Modifiers, Validators and Custom validators

For detailed information about the form configuration go to formconfig documentation

Validators

There are a few basic validators already included in the form generator.

  1. required
  2. empty
  3. maxValue
  4. minValue

Usage example

{
  "fieldName": "Minutes",
  "type": "number",
  "validators": [
    {
      "name": "minValue",
      "value": 1
    },
    {
      "name": "maxValue",
      "value": 59
    }
  ]
}

Modifiers

There are a few form modifiers which can modify the state of a field.

  1. setValidators
  2. setEnabled
  3. setVisibility
  4. setValue
  5. setMaxDate
  6. setMinDate

Usage example

{
  "fieldName": "Date",
  "type": "date",
},
{
  "fieldName": "Information",
  "type": "text",
  "disable": true,
  "regOnChange": {
    "parent": "Date",
    "callbacks": [
      {
        "method": "setEnabled",
        "param": true
      },
      {
        "method": "setValidator",
        "param": [
          {
            "name": "required",
            "value": true
          }
        ]
      }
    ]
  }
}

Custom validators

There is also a possibility to make your own validators. First you have to inject the FormValidatorService into you component.

import { FormValidatorService } from "angular-form-generator/src/custom-validators/validator.service";

constructor(private formValidatorService: FormValidatorService){}

Now you can add custom validators to the form generator. The addValidator function takes two arguments. First the name of the validator, second the validation function.

this.formValidatorService.addValidator("validator", (max:number) => {
  return (control: AbstractControl) => {
      var num = +control.value;
      if(control.value != "" && num > max){
          return { maxValueError: "Value must be lower than " + max};
      }
  };
});