1.1.6 • Published 2 years ago

vdr-react-form-manager v1.1.6

Weekly downloads
1
License
ISC
Repository
github
Last release
2 years ago

vdr-react-form-manager

vdr-react-form-manager is a form manager for React. With vdr-react-form-manager you can:

  • Manage forms
  • Manage inputs validation
  • Manage cross form inputs validation
  • add/remove/update inputs

Show it in action

Visit vdr-react-form-manager-sandbox website to see several examples of how to use the library.

Installation

  • npm
    • npm install -save vdr-react-form-manager
  • yarn
    • yarn add -save vdr-react-form-manager

Recommandation

  • Even if is possible to use vdr-react-form-manager for react js project, we precognize to use it with typescript

How use it

const { resetForm handleFormChange getFormValues getInputProps addInputs updateInputs removeInputs validateInputs updateFormProps emitLastFieldUpdated lastFieldUpdated isFormDisabled isFormValid isFormTouched isFormPristine formErrors formCustomsProps } = useFormManager(IFormInitalState)

IFormInitalState: is an object containing the initial form properties

Operationusagereturn valuedescription
resetFormresetForm()voidreset the form with the initialValues
handleFormChangehandleFormChange(onformOnChangeEvent)voidPass the formOnChangeEvent to this method
getFormValuesgetFormValues(){ k : v }return an object with form valuesk : input namev : input value(s)
getInputPropsgetInputProps(x)input propertiesreturn the input propertiesx : input name
addInputsaddInputs({ k : v })voidadd new input(s)k : input namev : input properties
updateInputsupdateInputs({ k : v })voidupdate input(s)k : input namev : input properties to update
removeInputsremoveInputs(x)voidremove input(s)x : array of input name
validateInputsvalidateInputs(x)voidwill check the validity of your form and inputs. Each input.errors and formErros will be regenared,x : null = all inputs will be checkedx : string[] = only the inputs is the list will be checked
updateFormPropsupdateFormProps(x)voidupdate the form propertiesx : FormProperties
emitLastFieldUpdatedemitLastFieldUpdated(x)voidconfigure if you want to receive the name of the latest input updatedx : true -> lastFieldUpdated will be settedx : false -> lastfieldUpdated = nulldefault is true
lastFieldUpdatedlastFieldUpdated{ inputName: x } or nullx : contains the name of the latest input updated if emitLastFieldUpdated = truereturn null if emitLastFieldUpdated = false
isFormDisabledisFormDisabledbooleancontains the form disabled status
isFormValidisFormValidbooleancontains the form validity status
isFormTouchedisFormTouchedbooleanThe form has been touched
isFormPristineisFormPristinebooleanThe form has not been modified yet
formErrorsformErrosxcontains the form errorsx : empty array if no errorsx : string[] array of string if the form has errors
formCustomsPropsformCustomsProps{ k : v }return an object with form valuesk : keyv: value

IFormInitialState

const { .... } = useFormManager(IFormInitialState)

You need to pass has parameter an object containing the initials props of your form.

PropertyNametypedescriptionoptional
formInputsIStateInputsObject containing the inputs propertiesfalse
formValidatorsarrayIFormValidatorArray containing functions which implement IFormValidator in order to validate the formtrue
formCustomsPropsobject{ k : v }k : custom property namev : custom property valuetrue
formClassNamesstring[]Array of strings who contains the initial form classestrue

IStateInputs: {K, V} object

Object containing the inputs properties

k : input name v : input properties object

input properties

PropertyNametypedescriptionoptional
namestringinput name name - required and uniquefalse
idstringinput idtrue
valueanyinput valuetrue
labelstringstring who contains the input labeltrue
isValidbooleanthe input content is validtrue
errorsstring[]contains the input erros.Empty array if no errorstrue
disabledbooleancontains the input disabled statustrue
classNamesstring[]contains the input classestrue
validatorsIFormInputValidator[]Array containing functions which implement IFormInputValidator in order to validate the inputtrue
availableValuesIFormInputAvailableValue[]Array containing objects which implement IFormInputAvailableValue in order to manage selectbox and multiple checkboxestrue
customPropsIKeyAnyobject{ k : v }k : custom property namev : custom property valuetrue
updateIdstringrandom string who changes every time that the input value changes.Ex: You can use this field to implement areequals function for React.memotrue
isTouchedbooleanThe input has been touchedtrue
isPristinebooleanThe input has not been modified yettrue

GitHub examples

Contains examples to manage a form using the library https://github.com/valentino-drappa/vdr-react-form-manager-sandbox

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.2

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago