17.0.0 • Published 2 months ago

@tft/crispr-forms v17.0.0

Weekly downloads
58
License
-
Repository
-
Last release
2 months ago

CRISPR Forms

Build forms like DNA builds life

Interactive docs

Description

Web development tends to involve building a lot of forms, and even though it can be repetitive it's not necessarily easy. Connecting templates to FormGroups takes time and there are a lot of opportunities to make mistakes along the way that can difficult to debug. Large form are difficult to keep organized, and long form templates are cumbersome to update.

Luckily, we've abstracted out the template work entirely, allowing the end developer to simply pass a config object to the tft-crispr-forms component and it will use these instructions to build out the form. This allows the end developer to focus on the business logic and not the template details.

We currently only support styling for Material Design, but support for other design systems is on our roadmap.

Supported Angular Material fields:

  • Autocomplete
  • Autocomplete Chiplist
  • Checkbox
  • Input
  • Select
  • Textarea
  • Slider
  • Datepicker
  • Button
  • Heading
  • Divider

More fields coming soon!

Super sweet features:

  • computed values: field values based on one or many other field values (fieldC === fieldA * fieldB)
  • dynamically disabled fields: disable a field reactively based on other field(s) values
  • configurations to handle all the features of each Angular Material field

Installation

CRISPR Forms has a few dependencies. First you'll need Angular Material. Usually you can just run ng add @angular/material. Find installation docs here.

The datepicker field require date-fns and @angular/material-date-fns-adapter to be installed. npm i date-fns @angular/material-date-fns-adapter

You will have also have to provide value for MAT_DATE_LOCALE in your root module.

import { MAT_DATE_LOCALE } from '@angular/material/core';
import { enUS } from 'date-fns/locale';


@NgModule({
  ...
  providers: [
    {
        provide: MAT_DATE_LOCALE,
        useValue: enUS,
    },
  ],
});

There are default messages for all the built in Angular validators, but they can easily overwritten by setting the errorDictionary field on the config input. Custom messages can also be created for custom validators.

Usage

With CRISPR Forms we've abstracted out form template entirely allowing you to generate your form by simply passing a configuration object to the tft-crispr-form component.

Interactive documentation can be found on Stackblitz here, with editable examples for most features.

In some-component.html we pass the configuration to the component and handleSubmit function to the submitted event.

<crispr-form
  [config]="config"
  (submitted)="handleSubmit($event)">
</crispr-form>

In some-component.ts we define the config and handleSubmit function.

export class DemoComponent implements OnInit {

  config: FormConfig = {
    fields: [
      // a basic input field in the form with the following configuration
      {
        controlType: ControlType.INPUT,
        label: 'I am a label on a text input',
        controlName: 'textInput',
        placeholder: 'I am a placeholder in a text input',
        validators: [Validators.required, Validators.minLength(5)],
      },
      {
        controlType: ControlType.SELECT,
        label: 'I am a label on a text input',
        controlName: 'textInput',
        options: [
          {label: 'option a', value: 'optionA'}
          {label: 'option a', value: 'optionA'}
        ],
        placeholder: 'I am a placeholder in a text input',
        validators: [Validators.required, Validators.minLength(5)],
      },
    ]
  }
}

Buttons can reset form or take custom events

See example here.

Datepicker can take a callback function to pass a class to specified fields

See example here. Be sure to check out the corresponding .scss file to see how we pass styles down to the cell class.

Pass Custom Components to CRISPR

Simply create a component and pass it as an argument to the component property.

export class CustomComponentComponent {

  customComponentConfig: FormConfig<CustomInputConfig> = {
    autocomplete: 'off',
    fields: [
      {
        component: CustomInputComponent,
        controlType: ControlType.CUSTOM,
        controlName: 'customComponent',
      },

Examples of how to extend current field behavior available here

Breaking Changest v13 => v14

Switch from MomentDateAdaptor to FnsDateAdapter

With momentjs shifting into maintenance mode, it no longer makes sense to use the MomentDateAdaptor, so we've switched to the FnsDateAdapter. This means that for DatepickerFieldConfigs the datepickerFilter, cellClassFunction, dateClass properties, instances of Moment will need to be replaced with Date.

v13

  datepickerFilter?: (date: Moment) => boolean;
  cellClassFunction?: MatCalendarCellClassFunction<Moment>;
  dateClass?: (parentGroup: FormGroup) => Observable<MatCalendarCellClassFunction<Moment>>;

v14

  datepickerFilter?: (date: Date) => boolean;
  cellClassFunction?: MatCalendarCellClassFunction<Date>;
  dateClass?: (parentGroup: FormGroup) => Observable<MatCalendarCellClassFunction<Date>>;

You'll also have to set up a date locale in your root module. See installation for details on how to set up the new adaptor.

Upcoming / In Progress

  • Creating modules for each component so that you can avoid importing unused components

  • Framework agnostic with Angular Elements

  • More examples of how to change field layout
  • The rest of the Angular Material fields:
    • Radio button
    • Slide toggle
    • Button toggle
15.0.0

2 months ago

17.0.0

2 months ago

14.0.2

1 year ago

14.0.1-rc.2

2 years ago

14.0.1-rc.0

2 years ago

14.0.1-rc.1

2 years ago

14.0.0

2 years ago

14.0.1

2 years ago

13.0.20

2 years ago

13.0.21

2 years ago

13.0.22

2 years ago

13.0.23

2 years ago

13.0.19

2 years ago

13.0.8

2 years ago

13.0.9

2 years ago

13.0.6

2 years ago

13.0.7

2 years ago

13.0.5

2 years ago

13.0.10

2 years ago

13.0.11

2 years ago

13.0.12

2 years ago

13.0.13

2 years ago

13.0.14

2 years ago

13.0.15

2 years ago

13.0.16

2 years ago

13.0.17

2 years ago

13.0.18

2 years ago

13.0.4

2 years ago

13.0.2

2 years ago

13.0.3

2 years ago

13.0.0

2 years ago

13.0.1

2 years ago

12.2.22

2 years ago

12.2.21

3 years ago

12.2.20

3 years ago

12.2.19

3 years ago

12.2.18

3 years ago

12.2.17

3 years ago

12.2.14

3 years ago

12.2.15

3 years ago

12.2.16

3 years ago

12.2.13

3 years ago

12.2.12

3 years ago

12.2.11

3 years ago

12.2.10

3 years ago

12.2.6

3 years ago

12.2.7

3 years ago

12.2.8

3 years ago

12.2.9

3 years ago

12.2.5

3 years ago

12.2.5-rc.0

3 years ago

12.2.4

3 years ago

12.2.1

3 years ago

12.2.2

3 years ago

12.2.3

3 years ago

12.2.0

3 years ago

12.1.2

3 years ago

12.1.1

3 years ago

12.1.0

3 years ago

12.0.1

3 years ago

12.0.0

3 years ago

11.2.0

3 years ago

11.3.1

3 years ago

11.3.0

3 years ago

11.1.5-rc.3

3 years ago

11.1.5-rc.2

3 years ago

11.1.5-rc.1

3 years ago

11.1.5-0

3 years ago

11.1.5-rc.0

3 years ago

11.1.4

3 years ago

11.1.3

3 years ago

11.1.2

3 years ago

11.1.1

3 years ago

11.1.0

3 years ago

11.0.2

3 years ago

11.0.1

3 years ago

11.0.0

3 years ago

10.1.4

4 years ago

10.1.3

4 years ago

10.1.1

4 years ago

10.1.2

4 years ago

10.1.0

4 years ago

10.0.4

4 years ago

10.0.3

4 years ago

10.0.2

4 years ago

10.0.1

4 years ago

10.0.0

4 years ago

9.0.4

4 years ago

9.0.3

4 years ago

9.0.2

4 years ago

9.0.1

4 years ago

9.0.0

4 years ago

8.9.4

4 years ago

8.9.3

4 years ago

8.9.2

4 years ago

8.9.1

4 years ago

8.9.0

4 years ago

8.8.0

4 years ago

8.7.7

4 years ago

8.7.6

4 years ago

8.7.5

4 years ago

8.7.4

4 years ago

8.7.3

4 years ago

8.7.2

4 years ago

8.7.1

4 years ago

8.7.0

4 years ago

8.6.0

4 years ago

8.5.1

4 years ago

8.5.0

4 years ago

8.4.3

4 years ago

8.4.2

4 years ago

8.4.0

4 years ago

8.3.2

4 years ago

8.3.3

4 years ago

8.3.0

4 years ago

8.3.1

4 years ago

8.2.3

4 years ago

8.2.2

4 years ago

8.2.1

4 years ago

8.2.0

4 years ago

8.1.1

4 years ago

8.1.0

4 years ago

8.0.2

4 years ago

8.0.1

4 years ago

8.0.0

4 years ago