0.2.3 • Published 4 years ago

clean-form v0.2.3

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

CleanForm

The library aims to provided powerfull forms handling without a lot of configuration.

BE CAREFULL : This library is not ready yet, and some breaking changes are expected shortly. Please do not use in production.

pipeline status

coverage report

Installation

In order to install this library in your project, you need to run this command :

npm install clean-form --save

Once installed, you can add it into your Angular project :

import { AppComponent } from './app.component'
import { CleanFormModule } from 'clean-form'

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

Usage

Now, you can start to use clean-forminto your project. clean-form only works with Angular reactive forms, so you need to have the have something like that into your .ts file :

// some.component.ts
import { FormBuilder, FormGroup } from '@angular/forms'

export class SomeComponent implements OnInit {
  public myForm: FormGroup

  constructor(public formBuilder: FormBuilder) {
    this.myForm = this.formBuilder.group({
      demo: 'Value of the demo field',
    })
  }
}

Then you can use this into your html files :

<!-- some.component.html -->

<clean-input [form]="myForm" name="demo"></clean-input>

And that's it, you should be able to use a generic field. Each component has specifics options it could handles to provide custom behaviors to each field.

clean-input Component

// some.component.ts
...
import { InputOptions } from 'clean-form'

export class SomeComponent implements OnInit {
  ...
  public myOptions: InputOptions = {
    label: `My field`,
    icon: `edit`,
    hint: `My small hint`,
    validators: {
      required: true,
    },
  }
  ...
}
<!-- some.component.html -->

<clean-input [form]="myForm" name="demo" [options]="myOptions"></clean-input>

In this case, field have a label, an icon, a hint and a validator, which prevent user the leave this field empty. Validator's errors are handle by clean-input and displayed when needed. In your .ts file, you should be able to use this.myForm.value or this.myForm.valid to get info.

See all options

clean-textarea

You could use <clean-textarea ...> to provide to your application a textarea field. Usage is same as below:

<!-- some.component.html -->

<clean-textarea [form]="myForm" name="demo" [options]="myOptions"></clean-textarea>

See all options

clean-select

You could use <clean-select ...> to provide to your application a select. In addition, you have to provide an array with data you want to select.

// some.component.ts
...
export class SomeComponent implements OnInit {
  ...
  choices: string[] = ['Choice 1', 'Choice 2', 'Choice 3',]
  ...
}
<!-- some.component.html -->

<clean-select [form]="myForm" name="demo" [options]="myOptions" [choices]="choices"></clean-select>

See all options

clean-swicth

You could use <clean-switch ...> to provide to your application a switch field wich handles true and false value. You could provide to your switch component a label and a reversedLabel. label is shown if switch is enable and reverseLabel if it isn't. If no reverseLabel is provided, label is shown everywhere.

// some.component.ts
...
import { SwitchOptions } from 'clean-form'

export class SomeComponent implements OnInit {
  ...
  public myOptions: SwitchOptions = {
    label: `My field is enable`,
    reversedLabel: `My field is disabled`,
  }
  ...
}
<!-- some.component.html -->

<clean-switch [form]="myForm" name="demo" [options]="myOptions"></clean-switch>

See all options

Options

Input options

NameTypeDefaultDescription
labelstring''Label which is displayed on top of input
hintstring''A small hint displayed below the input
iconstring''A material icon displayed on right
typestring'text'HTML input type
autocompleteAutocompleteOptions{}See autocomplete options
maskMaskOptions{}See mask options
validatorsValidatorsOptions{}See validator options
errorMessagesErrorMessagesOptions{}See errorMessages options
enableMaxlengthbooleanfalseDisplay or not the actuel legnth of field and the max value it could be
enableDefaultAutocompletebooleanfalseEnable default browsers autocompletion
enableValidColorbooleantrueWhen input is filled and valid, display a color
enableErrorColorbooleantrueWhen input is dirty and invalid, display a color
enableEraseButtonbooleantrueEnable an erase button to erase all input content

Autocomplete options

NameTypeDefaultDescription
suggestions[]string[][]List of all suggestions
hideSuggestionsOnMouseLeavebooleantrueHide suggestions when user leave the field
hideSuggestionsTimenumber500Time in ms before hiding suggestions
enableShowOnClickbooleantrueDisplay suggestions on click whenever there is no text
maxShownnumber50Max suggestions show in the same time

Mask options

NameTypeDefaultDescription
valuestring[]Mask definition
keepMaskbooleanfalseKeep mask in model value
suffixstringnullA suffix added to the mask
keepSuffixbooleanfalseKeep suffix in model value
alwaysSuffixbooleanfalseDisplay suffix even if there is no value
prefixstringnullA prefix added to the mask
keepPrefixbooleanfalseKeep prefix in model value
alwaysPrefixbooleanfalseDisplay prefix even if there is no value
thousandSeparatorstringSeparator char for thousands in number
decimalSeparatorstring.Separator char for decimal
canBeNegativebooleantrueNumber values can be negative

Validators options

NameTypeDefaultDescription
requiredbooleannullField value have to be filled
patternstringnullField value have to match the regex
maxlengthnumbernullField value have to have length smaller than specifed length
minlengthnumbernullField value have to have length bigger than specifed length
maxvaluenumbernullField value have to be smaller than specifed size
minvaluenumbernullField value have to be bigger than specifed size
0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.0.42

4 years ago

0.0.41

4 years ago

0.0.40

4 years ago

0.0.39

4 years ago

0.0.38

4 years ago

0.0.37

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.32

4 years ago

0.0.30

4 years ago

0.0.31

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.26

4 years ago

0.0.27

4 years ago

0.0.24

4 years ago

0.0.25

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago