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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@covalent/dynamic-forms

v8.24.1

Published

Teradata UI Platform Dynamic Forms Module

Downloads

2,339

Readme

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.

// Property values to be set in custom component
export interface ITdDynamicElementCustomConfig {
  [name: string]: any;
}

export interface ITdDynamicElementConfig {
  label?: string;
  name: string;
  hint?: string;
  type: TdDynamicType | TdDynamicElement | Type<any>;
  required = false;
  disabled?: boolean;
  min?: any;
  max?: any;
  minLength?: any;
  maxLength?: any;
  selections?: string[] | { value: any; label: string }[];
  multiple?: boolean;
  default?: any;
  flex?: number;
  validators?: ITdDynamicElementValidator[];
  customConfig?: ITdDynamicElementCustomConfig;
}

NOTE: For custom types, you need to implement a [control] property and use it in your underlying element.

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';
...
/* CUSTOM TYPE */
  template: `<label>{{label}}</label>
              <input [formControl]="control">
              <div *ngIf="errorMessageTemplate && control.errors"
                  class="tc-red-600"
                  [style.font-size.%]="'70'">
                <ng-template
                  [ngTemplateOutlet]="errorMessageTemplate"
                  [ngTemplateOutletContext]="{control: control, errors: control.errors}">
                </ng-template>
              </div>`,
})
export class DynamicCustomComponent {
  /* control property needed to properly bind the underlying element */
  control: FormControl;

  /* map any of the properties you passed in the config */
  label: string;

  /* map the error message template and use it anywhere you need to */
  errorMessageTemplate: TemplateRef<any>;
}
...
})
export class Demo {
  elements: ITdDynamicElementConfig[] = [{
    name: 'input',
    hint: 'hint',
    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,
    disabled: true,
  }, {
    name: 'select',
    type: TdDynamicElement.Select,
    required: true,
    multiple: false,
    selections: ['A','B','C'],
    default: 'A',
  }, {
    name: 'file-input',
    label: 'Label',
    type: TdDynamicElement.FileInput,
  }, {
    name: 'datepicker',
    label: 'Date',
    type: TdDynamicElement.Datepicker,
  }, {
    name: 'custom',
    label: 'Custom',
    type: DynamicCustomComponent,
    required: true,
  }];
}

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)

Running unit tests

Run nx test angular-dynamic-forms to execute the unit tests.