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

ng-flat-form

v1.2.2

Published

JSON driven dynamic, and reactive forms for Angular applications

Downloads

10

Readme

npm version Downloads


NgFlatForm

Angular 8+ static and dynamic forms library. Supports validation, async calls, and floating labels. Support for the following input types:

  • text
  • number
  • password
  • email
  • textarea
  • date
  • select

Getting started

1. Install ng-flat-form

Download from npm here. Or install locally by running:

  npm install ng-flat-form --save

2. Import the installed libraries

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { NgFlatFormModule } from 'ng-flat-form/lib/ng-flat-form.module';

import { AppComponent } from './app';

@NgModule({
  ...
  imports: [
    ...,
    NgFlatFormModule
  ],
})
export class AppModule {}

3. Create a flat-form in in your template

View Template

<div class="container">
  <ng-flat-form [form]="form"></ng-flat-form>
</div>

Component

  public form: FlatForm;

  constructor() { }

  ngOnInit(): void {
    this.initializeForm();
  }

  private initializeForm(): void {
    this.form = new FlatForm([
      new FlatFormControlGroup({
        title: '',
        description: '',
        controls: [
          new FlatFormControl({
            class: 'border-bottom half border-right',
            key: 'name',
            placeholder: 'Name',
            type: FlatFormControlType.INPUT_TEXT,
            required: true,
            showValidation: true,
            showLength: true,
          }),
          new FlatFormControl({
            class: 'border-bottom half',
            key: 'email',
            placeholder: 'Email',
            type: FlatFormControlType.INPUT_EMAIL,
            required: true,
            showValidation: true,
            manualValidation: true,
            showLength: true,
            onChange: this.handlePasswordChange,
            debounceTime: 1000,
          })
        ]);
      })
    ];
  }

4. Subscribe to form changes

Component

  public form: FlatForm;

  constructor() { }

  ngOnInit(): void {
    this.initializeForm();
    this.handleFormChange();
  }

  private handleFormChange(): void {
    this.form.statusChanges.subscribe((event: any) => {
      console.log(this.form.value);
    });
  }

5. Set form value

You can set the forms value in two ways: During initialization, by providing a value to the value property within FlatFormControl. Or by calling setForm({..}) on the FlatForm instance.

Component

  public form: FlatForm;

  constructor() { }

  ngOnInit(): void {
    this.initializeForm();
    this.handleFormChange();
    this.setForm();
  }

  private setForm(): void {
    this.form.setValue({
      name: 'Ron Swanson',
      email: '[email protected]'
    });
  }

Properties

FlatFormControl

| Property | Type | Required | Description | | ------------- |-------------| -----| ----| value | T | false | get/set the value of the control | key | string | true | the object key associated with the form value, also the corresponding key for json driven forms | placeholder | string | false | corresponds to the placeholder property of the element required | boolean | false | flag for whether the required field validator is applied to the given control disabled | boolean | false | flag for whether the given control will render as disabled type | FlatFormControlType | true | sets the control type (input, textarea, select) maxLength | number | false | corresponds to the maxLength property of the element minLength | number | false | corresponds to the minLength property of the element max | number | false | corresponds to the max property of the element min | number | false | corresponds to the min property of the element loading | boolean | false | flag controlling the visibility of the loading icon | hidden | boolean | false | corresponds to the hidden property of the element | showLoadingOnChange | boolean | false | flag for whether the loading icon should be shown when onChange is called | selectOptions | {key: string, value: string}[] = [] | false | array of key/value pairs to be used for select options | rows | number | false | corresponds to the rows attribute of the element | showValidation | boolean | false | flag for whether or not valid/invalid icons are shown while editing the given control | manualValidation | boolean | false | disables automatic validation allowing for manual updating of the given controls state | showLength | boolean | false | flat for whether or not dynamic character count is shown when maxLength is also defined | onChange | (event: any, control: FlatFormControl, controls: FlatFormControl[]) => void | | selectOptionsAsync | () => any | false | callback for retrieving select options dynamically | selectOptionsMap | { keyProperty: string, valueProperty: string } | false | function for mapping selectOptionsAsync to key/value pairs as defined for selectOptions | class | string | false | free form string for assigning custom classes to the given control | state | string | false | represents the status of the given control at any time (valid, invalid) | debounceTime | number | false | milliseconds delay between an input change event and the callback to onChange |