@noaestudio/forms
TypeScript icon, indicating that this package has built-in type declarations

0.10.1 • Public • Published

td-dynamic-forms

API Summary

Inputs

  • elements: ITdDynamicElementConfig[]
    • JS Object that will render the elements depending on its config.
    • [name] property is required.

Properties (Read only)

  • form: FormGroup
    • Getter property for dynamic [FormGroup].
  • valid: boolean
    • Getter property for [valid] of dynamic [FormGroup].
  • value: any
    • Getter property for [value] of dynamic [FormGroup].
  • errors: {[name: string]: any}
    • Getter property for [errors] of dynamic [FormGroup].
  • controls: {[key: string]: AbstractControl}
    • Getter property for [controls] of dynamic [FormGroup].

Methods

  • refresh: function
    • Refreshes the form and rerenders all validator/element modifications

Setup

Import the [CovalentDynamicFormsModule] in your NgModule:

import { CovalentDynamicFormsModule } from '@covalent/dynamic-forms';
@NgModule({
  imports: [
    CovalentDynamicFormsModule,
    ...
  ],
  ...
})
export class MyModule {}

Usage

td-dynamic-forms element generates a form dynamically

Pass an array of javascript objects that implement [ITdDynamicElementConfig] with the information to be rendered to the [elements] attribute.

export interface ITdDynamicElementConfig {
  label?: string;
  name: string;
  type: TdDynamicType | TdDynamicElement;
  required?: boolean;
  min?: any;
  max?: any;
  minLength?: string;
  maxLength?: string;
  selections?: any[];
  default?: any;
  validators?: ITdDynamicElementValidator[];
}

Example for HTML usage:

<td-dynamic-forms [elements]="elements">
  <ng-template let-element ngFor [ngForOf]="elements">
    <ng-template let-control="control" [tdDynamicFormsError]="element.name">
      <span *ngIf="control.touched || !control.pristine">
        <span *ngIf="control.hasError('required')">Required</span>
        <span *ngIf="control.hasError('min')">Min value: {{element.min}}</span>
        <span *ngIf="control.hasError('max')">Max value: {{element.max}}</span>
        <span *ngIf="control.hasError('minlength')">Min length value: {{element.minLength}}</span>
        <span *ngIf="control.hasError('maxlength')">Max length value: {{element.minLength}}</span>
      </span>
    </ng-template>
  </ng-template>
</td-dynamic-forms>
import { ITdDynamicElementConfig, TdDynamicElement, TdDynamicType } from '@covalent/dynamic-forms';
...
})
export class Demo {
  elements: ITdDynamicElementConfig[] = [{
    name: 'input',
    type: TdDynamicElement.Input,
    required: true,
  }, {
    name: 'textLength',
    label: 'Text Length',
    type: TdDynamicElement.Input,
    minLength: 4,
    maxLength: 12,
  }, {
    name: 'number',
    type: TdDynamicType.Number,
    min: 10,
    max: 80,
  }, {
    name: 'slider',
    label: 'Label',
    type: TdDynamicElement.Slider,
    required: true,
  }, {
    name: 'boolean',
    type: TdDynamicType.Boolean,
    default: false,
  }, {
    name: 'select',
    type: TdDynamicElement.Select,
    required: true,
    selections: ['A','B','C'],
    default: 'A',
  }, {
    name: 'file-input',
    label: 'Label',
    type: TdDynamicElement.FileInput,
  }, {
    name: 'datepicker',
    label: 'Date',
    type: TdDynamicElement.Datepicker,
  }];
}

Note: To use the datepicker you need to provide an implementation of DateAdapter.. click [here] for more information on the material datepicker(https://material.angular.io/components/datepicker/overview#choosing-a-date-implementation-and-date-format-settings)

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.10.14latest

Version History

VersionDownloads (Last 7 Days)Published
0.10.14
0.10.01
0.9.150
0.9.141
0.9.131
0.9.120
0.9.110
0.9.100
0.9.81
0.9.70
0.9.60
0.9.40
0.9.30
0.9.20
0.9.10
0.9.00
0.9.0-b0
0.8.150
0.8.140
0.8.130
0.8.120
0.8.110
0.8.100
0.8.90
0.8.80
0.8.70
0.8.60
0.8.50
0.8.30
0.8.20
0.8.10
0.8.00
0.7.70
0.7.61
0.7.51
0.7.40
0.7.30
0.7.20
0.7.10
0.7.00
0.6.100
0.6.90
0.6.70
0.6.60
0.6.50
0.6.41
0.6.31
0.6.21
0.6.00
0.5.120
0.5.110
0.5.100
0.5.90
0.5.80
0.5.70
0.5.61
0.5.50
0.5.40
0.5.10
0.5.00
0.4.70
0.4.60
0.4.50
0.4.40
0.4.31
0.4.10
0.4.00
0.3.110
0.3.100
0.3.90
0.3.80
0.3.70
0.3.61
0.3.50
0.3.40
0.3.30
0.3.20
0.3.11
0.3.01
0.2.40
0.2.30
0.2.20
0.2.10
0.2.00
0.1.70
0.1.60
0.1.50
0.1.41
0.1.30
0.1.20
0.1.10
0.1.00
0.0.70
0.0.60
0.0.51
0.0.40
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i @noaestudio/forms

Weekly Downloads

20

Version

0.10.1

License

MIT

Unpacked Size

3.23 MB

Total Files

113

Last publish

Collaborators

  • dev_noaestudio
  • alex_noa