# @gfrednand/dynamic-form

> This library help to manage material form fields

Latest version **0.0.20** (published 2021-02-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install @gfrednand/dynamic-form
pnpm add @gfrednand/dynamic-form
yarn add @gfrednand/dynamic-form
bun add @gfrednand/dynamic-form
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.20 |
| Published | 2021-02-24 |
| First published | 2021-02-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 962.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Gilbert Chami |
| Maintainers | ruzo, kelvinmbwilo, gfrednand |

## Links

- npm: https://www.npmjs.com/package/@gfrednand/dynamic-form
- Repository: https://github.com/gfrednand/DynamicForm
- Homepage: https://github.com/gfrednand/DynamicForm#readme
- Issues: https://github.com/gfrednand/DynamicForm/issues
- npm.io page: https://npm.io/package/@gfrednand/dynamic-form

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.0.0

## Recent versions

- 0.0.20 (latest) — 2021-02-24
- 0.0.19 — 2021-02-22
- 0.0.18 — 2021-02-22
- 0.0.17 — 2021-02-19
- 0.0.16 — 2021-02-19
- 0.0.15 — 2021-02-19
- 0.0.14 — 2021-02-19
- 0.0.13 — 2021-02-19
- 0.0.12 — 2021-02-19
- 0.0.11 — 2021-02-19
- 0.0.10 — 2021-02-18
- 0.0.9 — 2021-02-17
- 0.0.8 — 2021-02-17
- 0.0.7 — 2021-02-17
- 0.0.6 — 2021-02-17
- … 5 more at https://npm.io/package/@gfrednand/dynamic-form/versions

## README

# DynamicForm

* A simple dynamic form `component` to be used in component html.
* This components enhances the funtionality of Angular Form Fields.
* It is developed using `Angular >=8.0.0` and its newly introduced `ng g library` schematics.
* Library location: `projects/dynamic-form` directory of this repository.

## Installation

`npm i @gfrednand/dynamic-form`

## API

`import { DynamicFormModule } from '@gfrednand/dynamic-form'`<br>

### @Inputs()

| Input            | Type    | Required                   | Description                                                                                               |
| ---------------- | ------- | -------------------------- | --------------------------------------------------------------------------------------------------------- |
| fields           | array   | **YES**                    | [{key: '',...}]                                                                                           |
| form             |FormGroup| **YES**                    | FormGroup from angular form.                                                                              |
| isFormOpen       | boolean | Optional, default: true    | Used to reset form when form is closed                                                                    |
| loading          | boolean | Optional, default: false   | Used to show loading on the form                                                                          |
| loadingMessage   | string  | Optional, default: ''      | String to display when loading Ex: `Please Wait, Loading ...`                                             |
| formData         | object  | Optional, default: 'null'  | Initial form values                                                                                       |

### @Outputs()

| Output           | Type       | Required | Description                                            |
| ---------------- | ---------- | -------- | ------------------------------------------------------ |
| form             | FormGroup  | Optional | emits form group with values.                          |
| submit           | FormGroup  | Optional | emits action to trigger submit of form                 |
| fieldData        | FormGroup  | Optional | emits realtime values from the fields                  |
| closeForm        | FormGroup  | Optional | emits action to trigger close of form                  |

## Usage

1) Register the `DynamicFormModule` in your app module.
 > `import { DynamicFormModule } from '@gfrednand/dynamic-form'`

 ```typescript
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatAutocompleteModule, MatInputModule } from '@angular/material';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { DynamicFormModule } from '@gfrednand/dynamic-form';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    ReactiveFormsModule,
    MatInputModule,
    DynamicFormModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}
 ```

 2) Use the component selector `main-dynamic-form` in your component.

```typescript
import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { DynamicFormService,FieldConfig } from '@gfrednand/dynamic-form';
@Component({
  selector: 'app-component',
  template: `<h3>DynamicForm demo app using Angular Material</h3>
        <main-dynamic-form [fields]="fields" [isFormOpen]="true" [form]="form" (submit)="submitForm($event)">
        </main-dynamic-form>
`,
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  // Paramteres for the input type are defined below. The url is generated using `json-server`.
  // Please run your own instance of the json-server to use the the below url.


  constructor(private dynamicFormService: DynamicFormService,) {}

  form: FormGroup;
  fields: FieldConfig[    {
        type: FieldType.input,
        label: 'Title',
        rowClass: 'col12',
        key: 'title',
        validations: [{ message: 'Title is Required', validator: Validators.required, name: 'required', }],
    },
    {
        type: FieldType.textarea,
        label: 'Description',
        rowClass: 'col12',
        key: 'description',
        validations: [{ message: 'Description is Required', validator: Validators.required, name: 'required', }],
    },];

  ngOnInit() {
      this.form = this.dynamicFormService.createControl(this.fields, null);
  }
}
```

## Running the example in local env

* `npm i`
* Run `ng serve` for a dev server and running the demo app. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.

## Build the DynamicForm module

Run `ng build DynamicForm` to build the library. The build artifacts will be stored in the `dist/dynamic-form` directory. Use the `--prod` flag for a production build.

## Running unit tests

Run `ng test DynamicForm` to execute the unit tests via [Karma](https://karma-runner.github.io).

---
_Source: https://npm.io/package/@gfrednand/dynamic-form · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
