Giter Site home page Giter Site logo

ngx-formly-helpers's Introduction

ngx-formly-helpers

ngx-formly is an Angular library. It simplifies the creation of forms by a declaring the form model in the component. It supports different theme libraries like Material, Bootstrap, etc.

ngrx-formly-helper provides opt-in functions for form fields that are used most of the time. Especially with form-centric applications, it reduces the verbosity and makes the code more readable.

A demo is available on: https://stackblitz.com/github/rainerhahnekamp/ngx-formly-helpers-example

For example following ngx-formly config:

this.fields = [
  {
    key: "firstname",
    type: "input",
    templateOptions: { label: "Firstname" }
  },
  {
    key: "lastname",
    type: "input",
    templateOptions: { label: "Firstname", required: true }
  },
  {
    key: "birthday",
    type: "datepicker",
    templateOptions: { label: "Birthday" }
  },
  {
    key: "height",
    type: "input",
    templateOptions: { label: "Height (inches)" }
  },
  {
    key: "gender",
    type: "radio",
    templateOptions: {
      label: "Gender",
      options: [{ key: "m", label: "male" }, { key: "f", label: "female" }]
    }
  },
  {
    key: "continent",
    type: "select",
    templateOptions: {
      label: "Continent",
      options: continents
    }
  }
];

Can be reduced with ngx-formly-helpers to:

this.fields = [
  formly.text("firstname", "Firstname"),
  formly.required("lastname", "Lastname"),
  formly.date("birthday", "Geburtstag"),
  formly.number("height", "Height (inches)"),
  formly.radio("gender", "Gender", [
    { key: "m", label: "male" },
    { key: "f", label: "female" }
  ]),
  formly.select("continent", "Continent", continents)
];

Make sure that ngx-formly is installed and is working. Then simply add ngx-formly-helpers by

npm install ngx-formly-helper -D

You can then replace your form field configuration by using the functions provided by the formly object.

Helper methods exist for the common input elements in both required and non-required flavour:

  • text
  • requiredText
  • number
  • requiredNumber
  • hidden
  • checkbox
  • requiredCheckbox
  • select
  • requiredSelect
  • multiSelect
  • requiredMultiSelect
  • radio
  • requiredRadio
  • date
  • requiredDate
  • textArea
  • requiredTextArea

You also have can use the two factory methods to create your own helper functions:

  • field
  • requiredField

ngx-formly-helpers's People

Contributors

rainerhahnekamp avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.