@radicalbit/formbit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1180 -0
  3. package/dist/__tests__/check.test.d.ts +1 -0
  4. package/dist/__tests__/error.test.d.ts +1 -0
  5. package/dist/__tests__/initialize.test.d.ts +1 -0
  6. package/dist/__tests__/is-form-invalid.test.d.ts +1 -0
  7. package/dist/__tests__/is-form-valid.test.d.ts +1 -0
  8. package/dist/__tests__/live-validation.test.d.ts +1 -0
  9. package/dist/__tests__/remove.test.d.ts +1 -0
  10. package/dist/__tests__/reset-form.test.d.ts +1 -0
  11. package/dist/__tests__/set-error.test.d.ts +1 -0
  12. package/dist/__tests__/set-schema.test.d.ts +1 -0
  13. package/dist/__tests__/submit-form.test.d.ts +1 -0
  14. package/dist/__tests__/use-execute-callbacks.test.d.ts +1 -0
  15. package/dist/__tests__/use-formbit-context.test.d.ts +1 -0
  16. package/dist/__tests__/validate-all.test.d.ts +1 -0
  17. package/dist/__tests__/validate-form.test.d.ts +1 -0
  18. package/dist/__tests__/validate-sync-all.test.d.ts +1 -0
  19. package/dist/__tests__/validate.test.d.ts +1 -0
  20. package/dist/__tests__/write-all.test.d.ts +1 -0
  21. package/dist/__tests__/write.test.d.ts +1 -0
  22. package/dist/formbit-context.d.ts +9 -0
  23. package/dist/helpers/constants.d.ts +9 -0
  24. package/dist/helpers/obj-leaves.d.ts +3 -0
  25. package/dist/index.d.ts +4 -0
  26. package/dist/index.js +658 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/index.modern.js +654 -0
  29. package/dist/index.modern.js.map +1 -0
  30. package/dist/types/helpers.d.ts +2 -0
  31. package/dist/types/index.d.ts +418 -0
  32. package/dist/use-execute-callbacks.d.ts +11 -0
  33. package/dist/use-formbit.d.ts +7 -0
  34. package/dist/validate-sync-all.d.ts +2 -0
  35. package/package.json +90 -0
package/README.md ADDED
@@ -0,0 +1,1180 @@
1
+ # Formbit
2
+
3
+ Formbit is a **lightweight React state form library** designed to simplify form management within your applications. With **Formbit**, you can easily handle form state, validate user input, and submit data efficiently.
4
+
5
+ [![NPM](https://img.shields.io/npm/v/formbit.svg)](https://www.npmjs.com/package/formbit) [![license](https://badgen.net/badge/license/MIT)](./LICENSE)
6
+
7
+ ## Table of contents
8
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
9
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
10
+
11
+ - [Features](#features)
12
+ - [Abstract](#abstract)
13
+ - [Install](#install)
14
+ - [Getting started](#getting-started)
15
+ - [Local Development](#local-development)
16
+ - [Type Aliases](#type-aliases)
17
+ - [Check](#check)
18
+ - [CheckFnOptions](#checkfnoptions)
19
+ - [ClearIsDirty](#clearisdirty)
20
+ - [ErrorCallback](#errorcallback)
21
+ - [ErrorCheckCallback](#errorcheckcallback)
22
+ - [ErrorFn](#errorfn)
23
+ - [Errors](#errors)
24
+ - [Form](#form)
25
+ - [FormbitObject](#formbitobject)
26
+ - [GenericCallback](#genericcallback)
27
+ - [InitialValues](#initialvalues)
28
+ - [Initialize](#initialize)
29
+ - [IsDirty](#isdirty)
30
+ - [IsFormInvalid](#isforminvalid)
31
+ - [IsFormValid](#isformvalid)
32
+ - [LiveValidation](#livevalidation)
33
+ - [LiveValidationFn](#livevalidationfn)
34
+ - [Object](#object)
35
+ - [Remove](#remove)
36
+ - [ResetForm](#resetform)
37
+ - [SetError](#seterror)
38
+ - [SetSchema](#setschema)
39
+ - [SubmitForm](#submitform)
40
+ - [SuccessCallback](#successcallback)
41
+ - [SuccessCheckCallback](#successcheckcallback)
42
+ - [SuccessSubmitCallback](#successsubmitcallback)
43
+ - [Validate](#validate)
44
+ - [ValidateAll](#validateall)
45
+ - [ValidateFnOptions](#validatefnoptions)
46
+ - [ValidateForm](#validateform)
47
+ - [ValidateOptions](#validateoptions)
48
+ - [ValidationError](#validationerror)
49
+ - [ValidationFormbitError](#validationformbiterror)
50
+ - [ValidationSchema](#validationschema)
51
+ - [Write](#write)
52
+ - [WriteAll](#writeall)
53
+ - [WriteAllValue](#writeallvalue)
54
+ - [WriteFnOptions](#writefnoptions)
55
+ - [Writer](#writer)
56
+ - [License](#license)
57
+
58
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
59
+
60
+
61
+
62
+ ## Features
63
+
64
+ - Intuitive and easy-to-use form state management.
65
+ - Out of the box support for validation with [yup](https://github.com/jquense/yup).
66
+ - Support for handling complex forms with dynamic and nested fields.
67
+ - Seamless and flexible integration with React.
68
+ - Full Typescript support.
69
+
70
+ ## Abstract
71
+
72
+ The concept behind Formbit is to offer a lightweight library that assists you in managing all aspects of form state and error handling, while allowing you the flexibility to choose how to design the UI. It seamlessly integrates with various UI frameworks such as Antd, MaterialUI, or even plain HTML, as it provides solely a React hook that exposes methods to manage the form's React state. The responsibility of designing the UI remains entirely yours.
73
+
74
+ ## Install
75
+
76
+ ```bash
77
+ npm install --save formbit
78
+ ```
79
+
80
+ ```bash
81
+ yarn add formbit
82
+ ```
83
+
84
+ ## Getting started
85
+
86
+ ```jsx
87
+ import * as yup from 'yup';
88
+ import useFormbit from 'formbit';
89
+
90
+ const initialValues = { name: undefined, age: undefined };
91
+
92
+ const schema = yup.object().shape({
93
+ name: yup
94
+ .string()
95
+ .max(25, 'Name max length is 25 characters')
96
+ .required('Name is required'),
97
+
98
+ age: yup
99
+ .number()
100
+ .max(120, 'Age must be between 0 and 120')
101
+ .required('Age is required')
102
+ });
103
+
104
+ function Example() {
105
+ const { form, submitForm, write, error, isFormInvalid } = useFormbit({
106
+ initialValues,
107
+ yup: schema
108
+ });
109
+
110
+ const handleChangeName = ({ target: { value } }) => write('name', value);
111
+ const handleChangeAge = ({ target: { value } }) => write('age', value);
112
+ const onSubmit = () => console.log('Form Submitted!');
113
+ const onError = () => console.error('Form is invalid');
114
+ const handleSubmit = () => submitForm(onSubmit, onError);
115
+
116
+ return (
117
+ <>
118
+ <label name="name">Name</label>
119
+ <input
120
+ name="name"
121
+ onChange={handleChangeName}
122
+ type="text"
123
+ value={form.name}
124
+ />
125
+ <div>{error('name')}</div>
126
+
127
+ <label name="age">Age</label>
128
+ <input
129
+ name="age"
130
+ onChange={handleChangeAge}
131
+ type="number"
132
+ value={form.age}
133
+ />
134
+ <div>{error('age')}</div>
135
+
136
+ <button disabled={isFormInvalid()} onClick={handleSubmit} type="button">
137
+ Submit
138
+ </button>
139
+ </>
140
+ );
141
+ }
142
+
143
+ export default Example;
144
+ ```
145
+
146
+ ## Local Development
147
+ For local development we suggest using [Yalc](https://github.com/wclr/yalc) to test your local version of formbit in your projects.
148
+
149
+ <!-- START_TYPES_DOC -->
150
+ ## Type Aliases
151
+
152
+ ### Check
153
+
154
+ Ƭ **Check**\<`Values`\>: (`json`: [`Form`](#form), `options?`: [`CheckFnOptions`](#checkfnoptions)\<`Values`\>) => [`ValidationError`](#validationerror)[] \| `undefined`
155
+
156
+ Checks the given json against the form schema and returns and array of errors.
157
+ It returns undefined if the json is valid.
158
+
159
+ #### Type parameters
160
+
161
+ | Name | Type |
162
+ | :------ | :------ |
163
+ | `Values` | extends [`InitialValues`](#initialvalues) |
164
+
165
+ #### Type declaration
166
+
167
+ ▸ (`json`, `options?`): [`ValidationError`](#validationerror)[] \| `undefined`
168
+
169
+ ##### Parameters
170
+
171
+ | Name | Type |
172
+ | :------ | :------ |
173
+ | `json` | [`Form`](#form) |
174
+ | `options?` | [`CheckFnOptions`](#checkfnoptions)\<`Values`\> |
175
+
176
+ ##### Returns
177
+
178
+ [`ValidationError`](#validationerror)[] \| `undefined`
179
+
180
+ #### Defined in
181
+
182
+ [index.ts:14](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L14)
183
+
184
+ ___
185
+
186
+ ### CheckFnOptions
187
+
188
+ Ƭ **CheckFnOptions**\<`Values`\>: `Object`
189
+
190
+ Options object to change the behavior of the check method
191
+
192
+ #### Type parameters
193
+
194
+ | Name | Type |
195
+ | :------ | :------ |
196
+ | `Values` | extends [`InitialValues`](#initialvalues) |
197
+
198
+ #### Type declaration
199
+
200
+ | Name | Type |
201
+ | :------ | :------ |
202
+ | `errorCallback?` | [`ErrorCheckCallback`](#errorcheckcallback)\<`Values`\> |
203
+ | `options?` | [`ValidateOptions`](#validateoptions) |
204
+ | `successCallback?` | [`SuccessCheckCallback`](#successcheckcallback)\<`Values`\> |
205
+
206
+ #### Defined in
207
+
208
+ [index.ts:302](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L302)
209
+
210
+ ___
211
+
212
+ ### ClearIsDirty
213
+
214
+ Ƭ **ClearIsDirty**: () => `void`
215
+
216
+ Reset isDirty value to false
217
+
218
+ #### Type declaration
219
+
220
+ ▸ (): `void`
221
+
222
+ ##### Returns
223
+
224
+ `void`
225
+
226
+ #### Defined in
227
+
228
+ [index.ts:20](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L20)
229
+
230
+ ___
231
+
232
+ ### ErrorCallback
233
+
234
+ Ƭ **ErrorCallback**\<`Values`\>: (`writer`: [`Writer`](#writer)\<`Values`\>, `setError`: [`SetError`](#seterror)) => `void`
235
+
236
+ Invoked in case of errors raised by validation
237
+
238
+ #### Type parameters
239
+
240
+ | Name | Type |
241
+ | :------ | :------ |
242
+ | `Values` | extends [`InitialValues`](#initialvalues) |
243
+
244
+ #### Type declaration
245
+
246
+ ▸ (`writer`, `setError`): `void`
247
+
248
+ ##### Parameters
249
+
250
+ | Name | Type |
251
+ | :------ | :------ |
252
+ | `writer` | [`Writer`](#writer)\<`Values`\> |
253
+ | `setError` | [`SetError`](#seterror) |
254
+
255
+ ##### Returns
256
+
257
+ `void`
258
+
259
+ #### Defined in
260
+
261
+ [index.ts:25](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L25)
262
+
263
+ ___
264
+
265
+ ### ErrorCheckCallback
266
+
267
+ Ƭ **ErrorCheckCallback**\<`Values`\>: (`json`: [`Form`](#form), `inner`: [`ValidationError`](#validationerror)[], `writer`: [`Writer`](#writer)\<`Values`\>, `setError`: [`SetError`](#seterror)) => `void`
268
+
269
+ Invoked in case of errors raised by validation of check method
270
+
271
+ #### Type parameters
272
+
273
+ | Name | Type |
274
+ | :------ | :------ |
275
+ | `Values` | extends [`InitialValues`](#initialvalues) |
276
+
277
+ #### Type declaration
278
+
279
+ ▸ (`json`, `inner`, `writer`, `setError`): `void`
280
+
281
+ ##### Parameters
282
+
283
+ | Name | Type |
284
+ | :------ | :------ |
285
+ | `json` | [`Form`](#form) |
286
+ | `inner` | [`ValidationError`](#validationerror)[] |
287
+ | `writer` | [`Writer`](#writer)\<`Values`\> |
288
+ | `setError` | [`SetError`](#seterror) |
289
+
290
+ ##### Returns
291
+
292
+ `void`
293
+
294
+ #### Defined in
295
+
296
+ [index.ts:31](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L31)
297
+
298
+ ___
299
+
300
+ ### ErrorFn
301
+
302
+ Ƭ **ErrorFn**: (`path`: `string`) => `string` \| `undefined`
303
+
304
+ Returns the error message for the given path if any.
305
+ It doesn't trigger any validation
306
+
307
+ #### Type declaration
308
+
309
+ ▸ (`path`): `string` \| `undefined`
310
+
311
+ ##### Parameters
312
+
313
+ | Name | Type |
314
+ | :------ | :------ |
315
+ | `path` | `string` |
316
+
317
+ ##### Returns
318
+
319
+ `string` \| `undefined`
320
+
321
+ #### Defined in
322
+
323
+ [index.ts:39](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L39)
324
+
325
+ ___
326
+
327
+ ### Errors
328
+
329
+ Ƭ **Errors**: `Record`\<`string`, `string`\>
330
+
331
+ Object including all the registered errors messages since the last validation.
332
+ Errors are stored using the same path of the corresponding form values.
333
+
334
+ **`Example`**
335
+
336
+ If the form object has this structure:
337
+ ```json
338
+ {
339
+ "age": 1
340
+ }
341
+ ```
342
+ and age is a non valid field, errors object will look like this
343
+ ```json
344
+ {
345
+ "age": "Age must be greater then 18"
346
+ }
347
+ ```
348
+
349
+ #### Defined in
350
+
351
+ [index.ts:60](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L60)
352
+
353
+ ___
354
+
355
+ ### Form
356
+
357
+ Ƭ **Form**: \{ `__metadata?`: [`Object`](#object) } & [`Object`](#object)
358
+
359
+ Object containing the updated form
360
+
361
+ #### Defined in
362
+
363
+ [index.ts:65](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L65)
364
+
365
+ ___
366
+
367
+ ### FormbitObject
368
+
369
+ Ƭ **FormbitObject**\<`Values`\>: `Object`
370
+
371
+ Object returned by useFormbit() and useFormbitContextHook()
372
+ It contains all the data and methods needed to handle the form.
373
+
374
+ #### Type parameters
375
+
376
+ | Name | Type |
377
+ | :------ | :------ |
378
+ | `Values` | extends [`InitialValues`](#initialvalues) |
379
+
380
+ #### Type declaration
381
+
382
+ | Name | Type | Description |
383
+ | :------ | :------ | :------ |
384
+ | `check` | [`Check`](#check)\<`Partial`\<`Values`\>\> | Checks the given json against the form schema and returns and array of errors. It returns undefined if the json is valid. |
385
+ | `error` | [`ErrorFn`](#errorfn) | Returns the error message for the given path if any. It doesn't trigger any validation |
386
+ | `errors` | [`Errors`](#errors) | Object including all the registered errors messages since the last validation. Errors are stored using the same path of the corresponding form values. **`Example`** If the form object has this structure: ```json { "age": 1 } ``` and age is a non valid field, errors object will look like this ```json { "age": "Age must be greater then 18" } ``` |
387
+ | `form` | `Partial`\<`Values`\> | Object containing the updated form |
388
+ | `initialize` | [`Initialize`](#initialize)\<`Values`\> | Initialize the form with new initial values |
389
+ | `isDirty` | `boolean` | Returns true if the form is Dirty (user already interacted with the form), false otherwise. |
390
+ | `isFormInvalid` | [`IsFormInvalid`](#isforminvalid) | Returns true if the form is NOT valid It doesn't perform any validation, it checks if any errors are present |
391
+ | `isFormValid` | [`IsFormValid`](#isformvalid) | Returns true id the form is valid It doesn't perform any validation, it checks if any errors are present |
392
+ | `liveValidation` | [`LiveValidationFn`](#livevalidationfn) | Returns true if live validation is active for the given path |
393
+ | `remove` | [`Remove`](#remove)\<`Values`\> | This method updates the form state deleting value, setting isDirty to true. After writing, it validates all the paths contained into pathsToValidate (if any) and all the fields that have the live validation active. |
394
+ | `resetForm` | [`ResetForm`](#resetform) | Reset form to the initial state. Errors and liveValidation are set back to empty objects. isDirty is set back to false |
395
+ | `setError` | [`SetError`](#seterror) | Set a message(value) to the given error path. |
396
+ | `setSchema` | [`SetSchema`](#setschema)\<`Values`\> | Override the current schema with the given one. |
397
+ | `submitForm` | [`SubmitForm`](#submitform)\<`Values`\> | Perform a validation against the current form object, and execute the successCallback if the validation pass otherwise it executes the errorCallback |
398
+ | `validate` | [`Validate`](#validate)\<`Values`\> | This method only validate the specified path. Do not check for fields that have the live validation active. |
399
+ | `validateAll` | [`ValidateAll`](#validateall)\<`Values`\> | This method only validate the specified paths. Do not check for fields that have the live validation active. |
400
+ | `validateForm` | [`ValidateForm`](#validateform)\<`Partial`\<`Values`\>\> | This method validates the entire form and set the corresponding errors if any. |
401
+ | `write` | [`Write`](#write)\<`Values`\> | This method update the form state writing $value into the $path, setting isDirty to true. After writing, it validates all the paths contained into $pathsToValidate (if any) and all the fields that have the live validation active. |
402
+ | `writeAll` | [`WriteAll`](#writeall)\<`Values`\> | This method takes an array of [path, value] and update the form state writing all those values into the specified paths. It set isDirty to true. After writing, it validate all the paths contained into $pathToValidate and all the fields that have the live validation active. |
403
+
404
+ #### Defined in
405
+
406
+ [index.ts:341](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L341)
407
+
408
+ ___
409
+
410
+ ### GenericCallback
411
+
412
+ Ƭ **GenericCallback**\<`Values`\>: [`SuccessCallback`](#successcallback)\<`Values`\> \| [`ErrorCallback`](#errorcallback)\<`Values`\>
413
+
414
+ #### Type parameters
415
+
416
+ | Name | Type |
417
+ | :------ | :------ |
418
+ | `Values` | extends [`InitialValues`](#initialvalues) |
419
+
420
+ #### Defined in
421
+
422
+ [index.ts:67](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L67)
423
+
424
+ ___
425
+
426
+ ### InitialValues
427
+
428
+ Ƭ **InitialValues**: \{ `__metadata?`: [`Object`](#object) } & [`Object`](#object)
429
+
430
+ InitialValues used to setup formbit, used also to reset the form to the original version.
431
+
432
+ #### Defined in
433
+
434
+ [index.ts:77](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L77)
435
+
436
+ ___
437
+
438
+ ### Initialize
439
+
440
+ Ƭ **Initialize**\<`Values`\>: (`values`: `Partial`\<`Values`\>) => `void`
441
+
442
+ Initialize the form with new initial values
443
+
444
+ #### Type parameters
445
+
446
+ | Name | Type |
447
+ | :------ | :------ |
448
+ | `Values` | extends [`InitialValues`](#initialvalues) |
449
+
450
+ #### Type declaration
451
+
452
+ ▸ (`values`): `void`
453
+
454
+ ##### Parameters
455
+
456
+ | Name | Type |
457
+ | :------ | :------ |
458
+ | `values` | `Partial`\<`Values`\> |
459
+
460
+ ##### Returns
461
+
462
+ `void`
463
+
464
+ #### Defined in
465
+
466
+ [index.ts:71](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L71)
467
+
468
+ ___
469
+
470
+ ### IsDirty
471
+
472
+ Ƭ **IsDirty**: `boolean`
473
+
474
+ Returns true if the form is Dirty (user already interacted with the form), false otherwise.
475
+
476
+ #### Defined in
477
+
478
+ [index.ts:83](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L83)
479
+
480
+ ___
481
+
482
+ ### IsFormInvalid
483
+
484
+ Ƭ **IsFormInvalid**: () => `boolean`
485
+
486
+ Returns true if the form is NOT valid
487
+ It doesn't perform any validation, it checks if any errors are present
488
+
489
+ #### Type declaration
490
+
491
+ ▸ (): `boolean`
492
+
493
+ ##### Returns
494
+
495
+ `boolean`
496
+
497
+ #### Defined in
498
+
499
+ [index.ts:89](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L89)
500
+
501
+ ___
502
+
503
+ ### IsFormValid
504
+
505
+ Ƭ **IsFormValid**: () => `boolean`
506
+
507
+ Returns true id the form is valid
508
+ It doesn't perform any validation, it checks if any errors are present
509
+
510
+ #### Type declaration
511
+
512
+ ▸ (): `boolean`
513
+
514
+ ##### Returns
515
+
516
+ `boolean`
517
+
518
+ #### Defined in
519
+
520
+ [index.ts:95](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L95)
521
+
522
+ ___
523
+
524
+ ### LiveValidation
525
+
526
+ Ƭ **LiveValidation**: `Record`\<`string`, ``true``\>
527
+
528
+ Object including all the values that are being live validated.
529
+ Usually fields that fail validation (using one of the method that triggers validation)
530
+ will automatically set to be live-validated.
531
+
532
+ A value/path is live-validated when validated at every change of the form.
533
+
534
+ By default no field is live-validated
535
+
536
+ **`Example`**
537
+
538
+ If the form object has this structure:
539
+ ```json
540
+ {
541
+ "age": 1
542
+ }
543
+ ```
544
+ and age is a field that is being live-validated, liveValidation object will look like this
545
+ ```json
546
+ {
547
+ "age": "Age must be greater then 18"
548
+ }
549
+ ```
550
+
551
+ #### Defined in
552
+
553
+ [index.ts:121](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L121)
554
+
555
+ ___
556
+
557
+ ### LiveValidationFn
558
+
559
+ Ƭ **LiveValidationFn**: (`path`: `string`) => ``true`` \| `undefined`
560
+
561
+ Returns true if live validation is active for the given path
562
+
563
+ #### Type declaration
564
+
565
+ ▸ (`path`): ``true`` \| `undefined`
566
+
567
+ ##### Parameters
568
+
569
+ | Name | Type |
570
+ | :------ | :------ |
571
+ | `path` | `string` |
572
+
573
+ ##### Returns
574
+
575
+ ``true`` \| `undefined`
576
+
577
+ #### Defined in
578
+
579
+ [index.ts:127](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L127)
580
+
581
+ ___
582
+
583
+ ### Object
584
+
585
+ Ƭ **Object**: `Record`\<`string`, `unknown`\>
586
+
587
+ Generic object with string as keys
588
+
589
+ #### Defined in
590
+
591
+ [index.ts:133](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L133)
592
+
593
+ ___
594
+
595
+ ### Remove
596
+
597
+ Ƭ **Remove**\<`Values`\>: (`path`: `string`, `options?`: [`WriteFnOptions`](#writefnoptions)\<`Values`\>) => `void`
598
+
599
+ This method updates the form state deleting value and set isDirty to true.
600
+
601
+ After writing, it validates all the paths contained into pathsToValidate (if any)
602
+ and all the fields that have the live validation active.
603
+
604
+ #### Type parameters
605
+
606
+ | Name | Type |
607
+ | :------ | :------ |
608
+ | `Values` | extends [`InitialValues`](#initialvalues) |
609
+
610
+ #### Type declaration
611
+
612
+ ▸ (`path`, `options?`): `void`
613
+
614
+ ##### Parameters
615
+
616
+ | Name | Type |
617
+ | :------ | :------ |
618
+ | `path` | `string` |
619
+ | `options?` | [`WriteFnOptions`](#writefnoptions)\<`Values`\> |
620
+
621
+ ##### Returns
622
+
623
+ `void`
624
+
625
+ #### Defined in
626
+
627
+ [index.ts:152](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L152)
628
+
629
+ ___
630
+
631
+ ### ResetForm
632
+
633
+ Ƭ **ResetForm**: () => `void`
634
+
635
+ Reset form to the initial state.
636
+ Errors and liveValidation are set back to empty objects.
637
+ isDirty is set back to false
638
+
639
+ #### Type declaration
640
+
641
+ ▸ (): `void`
642
+
643
+ ##### Returns
644
+
645
+ `void`
646
+
647
+ #### Defined in
648
+
649
+ [index.ts:160](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L160)
650
+
651
+ ___
652
+
653
+ ### SetError
654
+
655
+ Ƭ **SetError**: (`path`: `string`, `value`: `string`) => `void`
656
+
657
+ Set a message(value) to the given error path.
658
+
659
+ #### Type declaration
660
+
661
+ ▸ (`path`, `value`): `void`
662
+
663
+ ##### Parameters
664
+
665
+ | Name | Type |
666
+ | :------ | :------ |
667
+ | `path` | `string` |
668
+ | `value` | `string` |
669
+
670
+ ##### Returns
671
+
672
+ `void`
673
+
674
+ #### Defined in
675
+
676
+ [index.ts:175](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L175)
677
+
678
+ ___
679
+
680
+ ### SetSchema
681
+
682
+ Ƭ **SetSchema**\<`Values`\>: (`newSchema`: [`ValidationSchema`](#validationschema)\<`Values`\>) => `void`
683
+
684
+ Override the current schema with the given one.
685
+
686
+ #### Type parameters
687
+
688
+ | Name | Type |
689
+ | :------ | :------ |
690
+ | `Values` | extends [`InitialValues`](#initialvalues) |
691
+
692
+ #### Type declaration
693
+
694
+ ▸ (`newSchema`): `void`
695
+
696
+ ##### Parameters
697
+
698
+ | Name | Type |
699
+ | :------ | :------ |
700
+ | `newSchema` | [`ValidationSchema`](#validationschema)\<`Values`\> |
701
+
702
+ ##### Returns
703
+
704
+ `void`
705
+
706
+ #### Defined in
707
+
708
+ [index.ts:181](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L181)
709
+
710
+ ___
711
+
712
+ ### SubmitForm
713
+
714
+ Ƭ **SubmitForm**\<`Values`\>: (`successCallback`: [`SuccessSubmitCallback`](#successsubmitcallback)\<`Values`\>, `errorCallback?`: [`ErrorCallback`](#errorcallback)\<`Partial`\<`Values`\>\>, `options?`: [`ValidateOptions`](#validateoptions)) => `void`
715
+
716
+ Perform a validation against the current form object, and execute the successCallback if the validation pass
717
+ otherwise it executes the errorCallback
718
+
719
+ #### Type parameters
720
+
721
+ | Name | Type |
722
+ | :------ | :------ |
723
+ | `Values` | extends [`InitialValues`](#initialvalues) |
724
+
725
+ #### Type declaration
726
+
727
+ ▸ (`successCallback`, `errorCallback?`, `options?`): `void`
728
+
729
+ ##### Parameters
730
+
731
+ | Name | Type |
732
+ | :------ | :------ |
733
+ | `successCallback` | [`SuccessSubmitCallback`](#successsubmitcallback)\<`Values`\> |
734
+ | `errorCallback?` | [`ErrorCallback`](#errorcallback)\<`Partial`\<`Values`\>\> |
735
+ | `options?` | [`ValidateOptions`](#validateoptions) |
736
+
737
+ ##### Returns
738
+
739
+ `void`
740
+
741
+ #### Defined in
742
+
743
+ [index.ts:188](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L188)
744
+
745
+ ___
746
+
747
+ ### SuccessCallback
748
+
749
+ Ƭ **SuccessCallback**\<`Values`\>: (`writer`: [`Writer`](#writer)\<`Values`\>, `setError`: [`SetError`](#seterror)) => `void`
750
+
751
+ Success callback invoked by some formbit methods when the operation is successful.
752
+
753
+ #### Type parameters
754
+
755
+ | Name | Type |
756
+ | :------ | :------ |
757
+ | `Values` | extends [`InitialValues`](#initialvalues) |
758
+
759
+ #### Type declaration
760
+
761
+ ▸ (`writer`, `setError`): `void`
762
+
763
+ ##### Parameters
764
+
765
+ | Name | Type |
766
+ | :------ | :------ |
767
+ | `writer` | [`Writer`](#writer)\<`Values`\> |
768
+ | `setError` | [`SetError`](#seterror) |
769
+
770
+ ##### Returns
771
+
772
+ `void`
773
+
774
+ #### Defined in
775
+
776
+ [index.ts:197](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L197)
777
+
778
+ ___
779
+
780
+ ### SuccessCheckCallback
781
+
782
+ Ƭ **SuccessCheckCallback**\<`Values`\>: (`json`: [`Form`](#form), `writer`: [`Writer`](#writer)\<`Values`\>, `setError`: [`SetError`](#seterror)) => `void`
783
+
784
+ Success callback invoked by the check method when the operation is successful.
785
+
786
+ #### Type parameters
787
+
788
+ | Name | Type |
789
+ | :------ | :------ |
790
+ | `Values` | extends [`InitialValues`](#initialvalues) |
791
+
792
+ #### Type declaration
793
+
794
+ ▸ (`json`, `writer`, `setError`): `void`
795
+
796
+ ##### Parameters
797
+
798
+ | Name | Type |
799
+ | :------ | :------ |
800
+ | `json` | [`Form`](#form) |
801
+ | `writer` | [`Writer`](#writer)\<`Values`\> |
802
+ | `setError` | [`SetError`](#seterror) |
803
+
804
+ ##### Returns
805
+
806
+ `void`
807
+
808
+ #### Defined in
809
+
810
+ [index.ts:203](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L203)
811
+
812
+ ___
813
+
814
+ ### SuccessSubmitCallback
815
+
816
+ Ƭ **SuccessSubmitCallback**\<`Values`\>: (`writer`: [`Writer`](#writer)\<`Values` \| `Omit`\<`Values`, ``"__metadata"``\>\>, `setError`: [`SetError`](#seterror), `clearIsDirty`: [`ClearIsDirty`](#clearisdirty)) => `void`
817
+
818
+ Success callback invoked by the submit method when the validation is successful.
819
+ Is the right place to send your data to the backend.
820
+
821
+ #### Type parameters
822
+
823
+ | Name | Type |
824
+ | :------ | :------ |
825
+ | `Values` | extends [`InitialValues`](#initialvalues) |
826
+
827
+ #### Type declaration
828
+
829
+ ▸ (`writer`, `setError`, `clearIsDirty`): `void`
830
+
831
+ ##### Parameters
832
+
833
+ | Name | Type |
834
+ | :------ | :------ |
835
+ | `writer` | [`Writer`](#writer)\<`Values` \| `Omit`\<`Values`, ``"__metadata"``\>\> |
836
+ | `setError` | [`SetError`](#seterror) |
837
+ | `clearIsDirty` | [`ClearIsDirty`](#clearisdirty) |
838
+
839
+ ##### Returns
840
+
841
+ `void`
842
+
843
+ #### Defined in
844
+
845
+ [index.ts:211](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L211)
846
+
847
+ ___
848
+
849
+ ### Validate
850
+
851
+ Ƭ **Validate**\<`Values`\>: (`path`: `string`, `options?`: [`ValidateFnOptions`](#validatefnoptions)\<`Values`\>) => `void`
852
+
853
+ This method only validate the specified path. Do not check for fields that have the
854
+ live validation active.
855
+
856
+ #### Type parameters
857
+
858
+ | Name | Type |
859
+ | :------ | :------ |
860
+ | `Values` | extends [`InitialValues`](#initialvalues) |
861
+
862
+ #### Type declaration
863
+
864
+ ▸ (`path`, `options?`): `void`
865
+
866
+ ##### Parameters
867
+
868
+ | Name | Type |
869
+ | :------ | :------ |
870
+ | `path` | `string` |
871
+ | `options?` | [`ValidateFnOptions`](#validatefnoptions)\<`Values`\> |
872
+
873
+ ##### Returns
874
+
875
+ `void`
876
+
877
+ #### Defined in
878
+
879
+ [index.ts:222](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L222)
880
+
881
+ ___
882
+
883
+ ### ValidateAll
884
+
885
+ Ƭ **ValidateAll**\<`Values`\>: (`paths`: `string`[], `options?`: [`ValidateFnOptions`](#validatefnoptions)\<`Values`\>) => `void`
886
+
887
+ This method only validate the specified paths. Do not check for fields that have the
888
+ live validation active.
889
+
890
+ #### Type parameters
891
+
892
+ | Name | Type |
893
+ | :------ | :------ |
894
+ | `Values` | extends [`InitialValues`](#initialvalues) |
895
+
896
+ #### Type declaration
897
+
898
+ ▸ (`paths`, `options?`): `void`
899
+
900
+ ##### Parameters
901
+
902
+ | Name | Type |
903
+ | :------ | :------ |
904
+ | `paths` | `string`[] |
905
+ | `options?` | [`ValidateFnOptions`](#validatefnoptions)\<`Values`\> |
906
+
907
+ ##### Returns
908
+
909
+ `void`
910
+
911
+ #### Defined in
912
+
913
+ [index.ts:229](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L229)
914
+
915
+ ___
916
+
917
+ ### ValidateFnOptions
918
+
919
+ Ƭ **ValidateFnOptions**\<`Values`\>: `Object`
920
+
921
+ Options object to change the behavior of the validate methods
922
+
923
+ #### Type parameters
924
+
925
+ | Name | Type |
926
+ | :------ | :------ |
927
+ | `Values` | extends [`InitialValues`](#initialvalues) |
928
+
929
+ #### Type declaration
930
+
931
+ | Name | Type |
932
+ | :------ | :------ |
933
+ | `errorCallback?` | [`ErrorCallback`](#errorcallback)\<`Partial`\<`Values`\>\> |
934
+ | `options?` | [`ValidateOptions`](#validateoptions) |
935
+ | `successCallback?` | [`SuccessCallback`](#successcallback)\<`Partial`\<`Values`\>\> |
936
+
937
+ #### Defined in
938
+
939
+ [index.ts:312](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L312)
940
+
941
+ ___
942
+
943
+ ### ValidateForm
944
+
945
+ Ƭ **ValidateForm**\<`Values`\>: (`successCallback?`: [`SuccessCallback`](#successcallback)\<`Values`\>, `errorCallback?`: [`ErrorCallback`](#errorcallback)\<`Values`\>, `options?`: [`ValidateOptions`](#validateoptions)) => `void`
946
+
947
+ This method validates the entire form and set the corresponding errors if any.
948
+
949
+ #### Type parameters
950
+
951
+ | Name | Type |
952
+ | :------ | :------ |
953
+ | `Values` | extends [`InitialValues`](#initialvalues) |
954
+
955
+ #### Type declaration
956
+
957
+ ▸ (`successCallback?`, `errorCallback?`, `options?`): `void`
958
+
959
+ ##### Parameters
960
+
961
+ | Name | Type |
962
+ | :------ | :------ |
963
+ | `successCallback?` | [`SuccessCallback`](#successcallback)\<`Values`\> |
964
+ | `errorCallback?` | [`ErrorCallback`](#errorcallback)\<`Values`\> |
965
+ | `options?` | [`ValidateOptions`](#validateoptions) |
966
+
967
+ ##### Returns
968
+
969
+ `void`
970
+
971
+ #### Defined in
972
+
973
+ [index.ts:235](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L235)
974
+
975
+ ___
976
+
977
+ ### ValidateOptions
978
+
979
+ Ƭ **ValidateOptions**: `YupValidateOptions`
980
+
981
+ Type imported from the yup library.
982
+ It represents the object with all the options that can be passed to the internal yup validation method,
983
+
984
+ Link to the Yup documentation [https://github.com/jquense/yup](https://github.com/jquense/yup)
985
+
986
+ #### Defined in
987
+
988
+ [index.ts:249](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L249)
989
+
990
+ ___
991
+
992
+ ### ValidationError
993
+
994
+ Ƭ **ValidationError**: `YupValidationError`
995
+
996
+ Type imported from the yup library.
997
+ It represents the error object returned when a validation fails
998
+
999
+ Link to the Yup documentation [https://github.com/jquense/yup](https://github.com/jquense/yup)
1000
+
1001
+ #### Defined in
1002
+
1003
+ [index.ts:325](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L325)
1004
+
1005
+ ___
1006
+
1007
+ ### ValidationFormbitError
1008
+
1009
+ Ƭ **ValidationFormbitError**: `Pick`\<[`ValidationError`](#validationerror), ``"message"`` \| ``"path"``\>
1010
+
1011
+ #### Defined in
1012
+
1013
+ [index.ts:240](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L240)
1014
+
1015
+ ___
1016
+
1017
+ ### ValidationSchema
1018
+
1019
+ Ƭ **ValidationSchema**\<`Values`\>: `ObjectSchema`\<`Values`\>
1020
+
1021
+ Type imported from the yup library.
1022
+ It represents any validation schema created with the yup.object() method
1023
+
1024
+ Link to the Yup documentation [https://github.com/jquense/yup](https://github.com/jquense/yup)
1025
+
1026
+ #### Type parameters
1027
+
1028
+ | Name | Type |
1029
+ | :------ | :------ |
1030
+ | `Values` | extends [`InitialValues`](#initialvalues) |
1031
+
1032
+ #### Defined in
1033
+
1034
+ [index.ts:169](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L169)
1035
+
1036
+ ___
1037
+
1038
+ ### Write
1039
+
1040
+ Ƭ **Write**\<`Values`\>: (`path`: keyof `Values` \| `string`, `value`: `unknown`, `options?`: [`WriteFnOptions`](#writefnoptions)\<`Values`\>) => `void`
1041
+
1042
+ This method update the form state writing $value into the $path, setting isDirty to true.
1043
+
1044
+ After writing, it validates all the paths contained into $pathsToValidate (if any)
1045
+ and all the fields that have the live validation active.
1046
+
1047
+ #### Type parameters
1048
+
1049
+ | Name | Type |
1050
+ | :------ | :------ |
1051
+ | `Values` | extends [`InitialValues`](#initialvalues) |
1052
+
1053
+ #### Type declaration
1054
+
1055
+ ▸ (`path`, `value`, `options?`): `void`
1056
+
1057
+ ##### Parameters
1058
+
1059
+ | Name | Type |
1060
+ | :------ | :------ |
1061
+ | `path` | keyof `Values` \| `string` |
1062
+ | `value` | `unknown` |
1063
+ | `options?` | [`WriteFnOptions`](#writefnoptions)\<`Values`\> |
1064
+
1065
+ ##### Returns
1066
+
1067
+ `void`
1068
+
1069
+ #### Defined in
1070
+
1071
+ [index.ts:258](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L258)
1072
+
1073
+ ___
1074
+
1075
+ ### WriteAll
1076
+
1077
+ Ƭ **WriteAll**\<`Values`\>: (`arr`: [`WriteAllValue`](#writeallvalue)\<`Values`\>[], `options?`: [`WriteFnOptions`](#writefnoptions)\<`Values`\>) => `void`
1078
+
1079
+ This method takes an array of [path, value] and update the form state writing
1080
+ all those values into the specified paths.
1081
+
1082
+ It set isDirty to true.
1083
+
1084
+ After writing, it validate all the paths contained into $pathToValidate and all
1085
+ the fields that have the live validation active.
1086
+
1087
+ #### Type parameters
1088
+
1089
+ | Name | Type |
1090
+ | :------ | :------ |
1091
+ | `Values` | extends [`InitialValues`](#initialvalues) |
1092
+
1093
+ #### Type declaration
1094
+
1095
+ ▸ (`arr`, `options?`): `void`
1096
+
1097
+ ##### Parameters
1098
+
1099
+ | Name | Type |
1100
+ | :------ | :------ |
1101
+ | `arr` | [`WriteAllValue`](#writeallvalue)\<`Values`\>[] |
1102
+ | `options?` | [`WriteFnOptions`](#writefnoptions)\<`Values`\> |
1103
+
1104
+ ##### Returns
1105
+
1106
+ `void`
1107
+
1108
+ #### Defined in
1109
+
1110
+ [index.ts:271](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L271)
1111
+
1112
+ ___
1113
+
1114
+ ### WriteAllValue
1115
+
1116
+ Ƭ **WriteAllValue**\<`Values`\>: [keyof `Values` \| `string`, `unknown`]
1117
+
1118
+ Tuple of [key, value] pair.
1119
+
1120
+ #### Type parameters
1121
+
1122
+ | Name | Type |
1123
+ | :------ | :------ |
1124
+ | `Values` | extends [`InitialValues`](#initialvalues) |
1125
+
1126
+ #### Defined in
1127
+
1128
+ [index.ts:278](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L278)
1129
+
1130
+ ___
1131
+
1132
+ ### WriteFnOptions
1133
+
1134
+ Ƭ **WriteFnOptions**\<`Values`\>: \{ `noLiveValidation?`: `boolean` ; `pathsToValidate?`: `string`[] } & [`ValidateFnOptions`](#validatefnoptions)\<`Values`\>
1135
+
1136
+ Options object to change the behavior of the write methods
1137
+
1138
+ #### Type parameters
1139
+
1140
+ | Name | Type |
1141
+ | :------ | :------ |
1142
+ | `Values` | extends [`InitialValues`](#initialvalues) |
1143
+
1144
+ #### Defined in
1145
+
1146
+ [index.ts:331](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L331)
1147
+
1148
+ ___
1149
+
1150
+ ### Writer
1151
+
1152
+ Ƭ **Writer**\<`Values`\>: `Object`
1153
+
1154
+ Internal form state storing all the data of the form (except the validation schema)
1155
+
1156
+ #### Type parameters
1157
+
1158
+ | Name | Type |
1159
+ | :------ | :------ |
1160
+ | `Values` | extends [`InitialValues`](#initialvalues) |
1161
+
1162
+ #### Type declaration
1163
+
1164
+ | Name | Type |
1165
+ | :------ | :------ |
1166
+ | `errors` | [`Errors`](#errors) |
1167
+ | `form` | `Values` |
1168
+ | `initialValues` | `Values` |
1169
+ | `isDirty` | [`IsDirty`](#isdirty) |
1170
+ | `liveValidation` | [`LiveValidation`](#livevalidation) |
1171
+
1172
+ #### Defined in
1173
+
1174
+ [index.ts:290](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L290)
1175
+
1176
+ <!-- END_TYPES_DOC -->
1177
+
1178
+ ## License
1179
+
1180
+ MIT © [Radicalbit (https://github.com/radicalbit)]