0.0.6 • Published 1 year ago

my-test-lib-jotunn v0.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

@halo-lab/ng-getform

To install package

npm install @halo-lab/ng-getform

To use the components

import { NgGetform, Input , Button, Checkbox, Select, RadioGroup } from '@halo-lab/ng-getform';
  • add imported component to imports in your component
  imports: [ NgGetForm, Input, Button, Checkbox, Select, RadioGroup]

Button accepts parameters

PropertyTypeNecessityDescription
btnLabelstringrequiredText inside button
btnTypestringoptionalType of button ('filled' or 'stroke'). Also can be 'wide' ( width : 100%). Default value - 'filled'
classNamestringoptionalClass name for custom styling

You can add events listeners directly on <lib-button> component.

Input accepts parameters

PropertyTypeNecessityDescription
controlFormControlrequiredVariable which control input value (new FormControl(yourValue : string)). Actually you can use all methods that are avalilable with Angular FormControl
inputIdstring or numberrequiredUnique ID of an input field
labelstringoptionalThe label of an input
placeholderstringoptionalInput placeholder (by default equal to label)
validator{type: string, message: string, value?: string or number}[]optionalArray of objects in the form of {type: validation type , message: text for unvalid tooltip, value?: for max, min, maxLength, minLength, pattern validators}. Validator's types may be: required, email , number , maxLength, minLength, max, min, pattern. For example: [ { type: 'required', message: 'Required field' },{ type: 'minLength', message: 'At least 2 characters', value: 2 },{ type: 'pattern', message: 'Only letters', value: '[a-zA-Z]+' }]
multiRowsbooleanoptionalWhen equal true, will be rendered <textarea>, otherwise a <input>
typestringoptionalInput type (default 'text')
classNamestringoptionalClass name for custom styling

Checkbox accepts parameters

PropertyTypeNecessityDescription
namestringrequiredThe name of an checkbox field
labelstringrequiredThe label of an checkbox
controlFormControlrequiredVariable which control checkbox value (new FormControl(yourValue : boolean)). Actually you can use all methods that are avalilable with Angular FormControl.
validator{type: string, message: string, value?: string or number}[]optionalArray of objects in the form of {type: validation type , message: text for unvalid tooltip, value?: string or number}. The validator's name may be: requiredTrue. For example: [{name: "requiredTrue", message: "Please accept our terms"}].
classNamestringoptionalClass name for custom styling

RadioGroup accepts parameters

PropertyTypeNecessityDescription
namestringrequiredThe name of an radio group input
labelstringrequiredhe label of an radio group
items{name:string,value:string}[]requiredArray of options
requiredFormControlrequiredVariable which control radio group value (new FormControl(yourValue : string or number)). Actually you can use all methods that are avalilable with Angular FormControl.
validator{type: string, message: string, value?: string or number}[]optionalArray of objects in the form of {type: validation type , message: text for unvalid tooltip, value?: string or number}. The validator's name may be: required. For example: [{name: "required", message: "You must select one option"}].
orientationstring (vertical or horizontal)optionalProperty that allow you to control buttons group orientation. Default value : vertical
classNamestringoptionalClass name for custom styling

Select accepts parameters

PropertyTypeNecessityDescription
placeholderstringrequiredQuestion before select component
optionsstring[]requiredArray of options
controlFormControlrequiredVariable which control radio group value (new FormControl(yourValue : string)). Actually you can use all methods that are avalilable with Angular FormControl.
validator{type: string, message: string, value?: string or number}[]optionalArray of objects in the form of {type: validation type , message: text for unvalid tooltip, value?: string or number}. The validator's name may be: required. For example: [{name: "required", message: "Please select your favourite fruit"}].
searchEnabledbooleanoptionalEnable/disable search bar for select options
classNamestringoptionalClass name for custom styling

NgGetform accepts parameters

PropertyTypeNecessityDescription
targetUrlstringrequiredThe url of your endpoint on getform
formGroupFormGrouprequiredA FormGroup aggregates the values of each child FormControl into one object, with each control name as the key. It calculates its status by reducing the status values of its children.
successCallbackFunctionoptionalFunction that will be called after successful submission of the form data on getform.io
classNamestringoptionalClass name for custom form styling

Example of usage

HTML

  <lib-ng-getform
    [targetUrl]="'https://getform.io/your-getform-id'"
    [formGroup]="formGroup"
    [successCallback]="callback"
  >
    <lib-input
      [label]="'Name'"
      [placeholder]="'Please write your name'"
      [control]="formGroup.controls['name']"
      [validator]="[
        { type: 'required', message: 'Required field' },
        { type: 'minLength', message: 'At least 2 characters', value: 2 },
        { type: 'pattern', message: 'Only letters', value: '[a-zA-Z]+' }
      ]"
    ></lib-input>
    <lib-input
      [label]="'E-mail'"
      [placeholder]="'Please write your email'"
      [control]="formGroup.controls['email']"
      [validator]="[
        { type: 'required', message: 'Required field' },
        { type: 'email', message: 'Unvalid e-mail' }
      ]"
    ></lib-input>
    <lib-radio-group
      [label]="'Choose your favourite sport'"
      [orientation]="'vertical'"
      [items]="sportsOptions"
      [control]="formGroup.controls['sport']"
      [validator]="[
        { type: 'required', message: 'You need to select option!' }
      ]"
    ></lib-radio-group>
    <lib-select
      [placeholder]="'Choose your favourite fruit'"
      [searchEnabled]="true"
      [options]="fruitsArr"
      [control]="formGroup.controls['fruit']"
      [validator]="[{ type: 'required', message: 'Select one fruit!' }]"
    ></lib-select>
    <lib-checkbox
      [name]="'confirmation'"
      [label]="'Are you sure about that?'"
      [control]="formGroup.controls['confirmation']"
      [validator]="[{ type: 'requiredTrue', message: 'Must be checked' }]"
    ></lib-checkbox>
    <lib-button [btnLabel]="'Send Form'" [btnType]="'wide filled'"></lib-button>
  </lib-ng-getform>

TS

import { FormControl, FormGroup } from '@angular/forms';
import { NgGetform, Input , Button, Checkbox, Select, RadioGroup } from '@halo-lab/ng-getform'

formGroup: FormGroup = new FormGroup({
    name: new FormControl(''),
    email: new FormControl(''),
    fruit: new FormControl(null),
    sport: new FormControl(null),
    confirmation: new FormControl(false)
  })

  sportsOptions: { name: string, value: string }[] =
    [{ name: 'soccer', value: 'soccer' },
    { name: 'hockey', value: 'hockey' },
    { name: 'tenis', value: 'tenis' },
    { name: 'basketball', value: 'basketball' },
    { name: 'formula 1', value: 'formula-1' }];
  fruitsArr: string[] = ['Banana',
    'Mango',
    'Pear',
    'Apple',
    'Orange'
  ];

  callback() {
    console.log('hello from callback');
  }

Word from author

Have fun ✌️

0.0.3

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.6

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago