@ezderm/ez-form v1.26.0
Basics
- Keep input value and error in state
- Handle
onChangeevent on input to update state (validation is performed here) - "externalized"
formElement(formElements file) defaultValue*label,label2
Additional requirements
- Trigger an action on input change (get some data, update another field, …)
- Validate another field (
validateAnotherField) on input change (i.e. password confirmation - when password is changed, confirmation should be validated again) withDependancyvalidation- Update another field(s) on change (i.e country-state selects or clinics-primary clinic, address same as patient's)
- multiselect
onValueClick isVisible(invisible items don't pass through validation nor are included inprepareForServerresult) (probably will be a part of schema)disabledfield- pass
additionalPropsspecific to underling element (i.e. options for select, optionRenderer, labelIcon, etc.) * dynamic sub-foms - be able to dynamically extend schema (i.e add contact method (1 field), add address info(group of fields))
Form utils
- init form from schema with initial data
- prepare form data for server (withAdditionalProps option for selects)
- clone form data to be able to revert form to some previous state
- update form state -
setSchemaStateValue,setSchemaStateValues(Bulk) *validatefunction
Differences with original schema:
withDependancyvalidation: no wraper functionwithDependancy, instead we skip validator function if args havedependencyFieldand dependency value is different than in state or the state value is falsyif we pass
dependencyInValidationArgs: true in val rule args, than comparedependencyValuewith value passed as arg in validate functionTests
- init.test
- init default value from schema (keep value in state)
- default isVisible flag in schema
- init values with second arg
-
labelandlabel2- select init with obj/string that is/is't in options - multi select ([] with obj/string that is/is't in options) - update.test - update field value in state onChange
- validation.test
- validate value on
inputChage- support string and intl error messages (message is handled in formElemet) - support default and custom error messages - args property for validation func (based on another schema field or fixed arg) - validate another field - prevent cyclically validation with validate another field (validate another field only on field change) - with dependancy validation render.test - render componet based on
isVisibleprop in arg - disable component based ondisabledprop in arg -onChangecb for text input and selet -onInputChangefor selectprepareForServer.test
- setSchemaStateValue.test
- getSchemaStateValue.test
- cloneStateValues.test
- init.test
- init default value from schema (keep value in state)
- default isVisible flag in schema
- init values with second arg
-
* npm publish --access publicPublish
1) commit all work with clean Flow and Eslint warning output 2) make sure that all tests are passing 3) increment version in package.json 4) run "npm publish --access public"
Flow:
- check type of variable in file: flow type-at-pos /path/to/file.js 6 6
API
Table of Contents
- useForm
- getSchemaStateValue
- setSchemaStateValue
- setSchemaStateValueBulk
- validate
- prepareForServer
- cloneStateValues
- addDynamicItem
- removeDynamicItem
- RenderFieldFunctionArgs
- ComponentType
- IntlMessageDescriptor
- IntlMessage
- InputType
- FormElement
- Label
- ErrorMessage
- ValidationRule
- SelectValue
- MultiSelectValue
- SchemaValue
- MaskedInputEventTarget
- MaskedInputSynteticEvent
- StandardFieldMetadata
- DynamicFieldMetadata
- FieldMetadata
- Schema
- SetSchemaStateArgs
- ValuesMap
- SetSchemaStateValueBulkArgs
- StandardFieldState
- DynamicFieldState
- FieldState
- FormState
- InitValuesMap
- AddDynamicItemArgs
- RemoveDynamicItemArgs
useForm
useForm
Parameters
schemaSchemaschemaValuesInitValuesMap?
getSchemaStateValue
getSchemaStateValue
Parameters
fieldNamestring
Returns SchemaValue
setSchemaStateValue
setSchemaStateValue
Parameters
$0.fullFieldName$0.newValue$0.skipValidation(optional, defaultfalse)$0.onComplete
Returns void
setSchemaStateValueBulk
setSchemaStateValueBulk
Parameters
$0SetSchemaStateValueBulkArgs$0.valuesMap$0.skipValidation(optional, defaultfalse)$0.onComplete
validate
validate
Parameters
dependencyArgs{}? some additional arguments thet we want to pass to validation function
Returns boolean
prepareForServer
prepareForServer - function that returns object with pairs fieldName: value
Returns ValuesMap
cloneStateValues
cloneStateValues - very similar to prepareForServer. The only difference is that it doesn't transform values at all, i.e. select/multiselect, trimming, etc
Returns {}
addDynamicItem
addDynamicItem
Parameters
$0.dynamicFieldName$0.initData
removeDynamicItem
removeDynamicItem
Parameters
$0.dynamicFieldName$0.index
RenderFieldFunctionArgs
RenderFieldFunctionArgs
Properties
useSecondLabelboolean?isVisibleboolean?disabledboolean?valueSchemaValue
ComponentType
Component from React
IntlMessageDescriptor
IntlMessageDescriptor
Properties
IntlMessage
IntlMessage
Properties
descriptorIntlMessageDescriptorvalues{}?
InputType
InputType
Type: ("TEXT_INPUT" | "MASKED_TEXT_INPUT" | "SELECT_INPUT" | "MULTISELECT" | "CHECKBOX" | "RADIOGROUP" | "TEXT_AREA")
FormElement
FormElement
Properties
typeInputTypeComponentComponentType<{value: any, error: string, onChange: function (any): void}>
Label
Label
Type: (string | IntlMessage)
ErrorMessage
ErrorMessage
Type: (string | IntlMessage)
ValidationRule
ValidationRule
Properties
fnfunction (value: string, message: ErrorMessage?, args: {}?, state: {}?): stringmessageErrorMessage?args{dependencyField: string?, dependencyValue: any?, dependencyInValidationArgs: boolean?}?validateAnotherFieldstring?
SelectValue
SelectValue
Type: (string | {value: (string | number), label: string} | null)
MultiSelectValue
MultiSelectValue
Type: (Array[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | Array<{value: (string | number), label: string}>)
SchemaValue
SchemaValue
Type: (string | number | boolean | Array[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | SelectValue | void | {})
MaskedInputEventTarget
MaskedInputEventTarget
Properties
rawValuestring
MaskedInputSynteticEvent
MaskedInputSynteticEvent
Properties
anytargetMaskedInputEventTarget
StandardFieldMetadata
StandardFieldMetadata
Properties
defaultValueSchemaValueformElementFormElementlabelLabel?label2Label?validationRulesArray<ValidationRule>?isVisibleboolean?
DynamicFieldMetadata
DynamicFieldMetadata
Properties
dynamicSchemaItem{}
FieldMetadata
FieldMetadata
Type: (StandardFieldMetadata | DynamicFieldMetadata)
Schema
Schema - object that serves as a map of field names and its data
SetSchemaStateArgs
SetSchemaStateArgs
Properties
fullFieldNamestringnewValueSchemaValueskipValidationbooleanonCompleteFunction
ValuesMap
ValuesMap - object that maps each fieldName with its (new) value
SetSchemaStateValueBulkArgs
SetSchemaStateValueBulkArgs
Properties
StandardFieldState
StandardFieldState
Properties
valueanyerrorstringvalidationRulesArray<ValidationRule>isVisibleboolean
DynamicFieldState
DynamicFieldState
Properties
isDynamictruevalueArray<{}>
FieldState
FieldState
Type: (StandardFieldState | DynamicFieldState)
FormState
FormState
InitValuesMap
InitValuesMap
AddDynamicItemArgs
AddDynamicItemArgs
Properties
dynamicFieldNamestringinitDataInitValuesMap
RemoveDynamicItemArgs
RemoveDynamicItemArgs
Properties
2 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago