22
33A simple form library using react hooks
44
5-
65## Features
76
87- Reasonably typesafe
@@ -12,13 +11,13 @@ A simple form library using react hooks
1211- Supports automatic dependency tracking
1312- Supports restore point
1413
15- ## Introduction
14+ ## API
1615
1716The library exposes three react hooks to define a form.
1817
19181 . useForm
20- 2 . useArrayField
21- 3 . useObjectField
19+ 2 . useFormArray
20+ 3 . useFormObject
2221
2322### useForm
2423
@@ -104,7 +103,7 @@ The array schema is an object with these properties:
104103| property| description|
105104| ----| ----|
106105| validation| Function to validate the array|
107- | members | Function that defines the schema for each item of the array|
106+ | member | Function that defines the schema for each item of the array|
108107| keySelector| Function that defines the unique key for each item of the array|
109108
110109### Literal Schema
@@ -114,7 +113,7 @@ The literal schema is an object with these properties:
114113| property| description|
115114| ----| ----|
116115| required| If defined, the literal will be required|
117- | requiredCondition | If defined, this function will be used to check required condition|
116+ | requiredValidation | If defined, this function will be used to check required condition|
118117| defaultValue| If defined, the literal value will fallback to this value|
119118| forceValue| If defined, the literal value will always be this value|
120119| validations| Array of functions to validate the literal|
@@ -138,21 +137,79 @@ The library provides these validation function:
138137- emailCondition
139138- urlCondition
140139
141- #### Symbols
140+ ## Helper Functions
141+
142+ ### getErrorObject
143+
144+ Function to convert leaf error to object error
145+
146+ ### getErrorString
147+
148+ Function to convert object error or array error to string error
149+
150+ ### removeNull
151+
152+ Function to recursively remove ` null ` values from an object
153+
154+ ### createSubmitHandler
155+
156+ Predefined function to define submit handler for html form
157+
158+ | argument| description|
159+ | ----| ----|
160+ | validator| Function to trigger form validation|
161+ | setError| Function to set form error|
162+ | successCallback| Callback for validation success|
163+ | failureCallback| Callback for validation failure|
164+
165+ The return value is the function that can be passed to form ` onSubmit ` prop
166+
167+ ### addCondition
168+
169+ Predefined function to add conditions on schema fields
170+
171+ | argument| description|
172+ | ----| ----|
173+ | schema| Fields of the object schema|
174+ | value| Value of the object|
175+ | dependentKeys| Keys of the object that are used to define the condition|
176+ | valueKeys| Keys of the object that are affected by the condition|
177+
178+ The return value is the updated fields of the object schema
179+
180+ ## Core Functions
181+
182+ ### accumulateValues
183+
184+ Function to get validated value from form value and form schema
185+
186+ ### accumulateErrors
187+
188+ Function to get form error from form value and form schema
189+
190+ ### accumulateDifferentialErrors
191+
192+ Function to get differential form error from form value and form schema
193+
194+ ### analyzeErrors
195+
196+ Function to identify if form has errored from the form error
197+
198+ ## Symbols
142199
143- ##### nonFieldError
200+ ### nonFieldError
144201
145202Symbol to access non field error on errors returned by ` useForm `
146203
147- ##### fieldDependencies
204+ ### fieldDependencies
148205
149206Symbol to define field dependencies on object schema
150207
151- ##### undefinedValue
208+ ### undefinedValue
152209
153210Symbol to define ` undefined ` on ` forceValue ` and ` defaultValue ` on literal schema
154211
155- ##### nullValue
212+ ### nullValue
156213
157214Symbol to define ` null ` on ` forceValue ` and ` defaultValue ` on literal schema
158215
0 commit comments