@radicalbit/formbit 1.1.0 → 1.2.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.
package/README.md CHANGED
@@ -33,6 +33,7 @@ Formbit is a **lightweight React state form library** designed to simplify form
33
33
  - [LiveValidationFn](#livevalidationfn)
34
34
  - [Object](#object)
35
35
  - [Remove](#remove)
36
+ - [RemoveAll](#removeall)
36
37
  - [ResetForm](#resetform)
37
38
  - [SetError](#seterror)
38
39
  - [SetSchema](#setschema)
@@ -107,14 +108,20 @@ function Example() {
107
108
  yup: schema
108
109
  });
109
110
 
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);
111
+ const handleChangeName = ({ target: { value } }) => { write('name', value); }
112
+ const handleChangeAge = ({ target: { value } }) => { write('age', value); }
113
+ const handleSubmit = () => {
114
+ submitForm(
115
+ (writer) => {
116
+ console.log("Your validated form is: ", writer.form)
117
+ },
118
+ (writer) => {
119
+ console.error("The validation errors are: ", writer.errors)
120
+ });
121
+ }
115
122
 
116
123
  return (
117
- <>
124
+ <div>
118
125
  <label name="name">Name</label>
119
126
  <input
120
127
  name="name"
@@ -136,7 +143,7 @@ function Example() {
136
143
  <button disabled={isFormInvalid()} onClick={handleSubmit} type="button">
137
144
  Submit
138
145
  </button>
139
- </>
146
+ </div>
140
147
  );
141
148
  }
142
149
 
@@ -179,7 +186,7 @@ It returns undefined if the json is valid.
179
186
 
180
187
  #### Defined in
181
188
 
182
- [index.ts:14](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L14)
189
+ [index.ts:14](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L14)
183
190
 
184
191
  ___
185
192
 
@@ -205,7 +212,7 @@ Options object to change the behavior of the check method
205
212
 
206
213
  #### Defined in
207
214
 
208
- [index.ts:302](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L302)
215
+ [index.ts:309](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L309)
209
216
 
210
217
  ___
211
218
 
@@ -225,7 +232,7 @@ Reset isDirty value to false
225
232
 
226
233
  #### Defined in
227
234
 
228
- [index.ts:20](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L20)
235
+ [index.ts:20](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L20)
229
236
 
230
237
  ___
231
238
 
@@ -258,7 +265,7 @@ Invoked in case of errors raised by validation
258
265
 
259
266
  #### Defined in
260
267
 
261
- [index.ts:25](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L25)
268
+ [index.ts:25](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L25)
262
269
 
263
270
  ___
264
271
 
@@ -293,7 +300,7 @@ Invoked in case of errors raised by validation of check method
293
300
 
294
301
  #### Defined in
295
302
 
296
- [index.ts:31](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L31)
303
+ [index.ts:31](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L31)
297
304
 
298
305
  ___
299
306
 
@@ -320,7 +327,7 @@ It doesn't trigger any validation
320
327
 
321
328
  #### Defined in
322
329
 
323
- [index.ts:39](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L39)
330
+ [index.ts:39](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L39)
324
331
 
325
332
  ___
326
333
 
@@ -348,7 +355,7 @@ and age is a non valid field, errors object will look like this
348
355
 
349
356
  #### Defined in
350
357
 
351
- [index.ts:60](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L60)
358
+ [index.ts:60](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L60)
352
359
 
353
360
  ___
354
361
 
@@ -360,7 +367,7 @@ Object containing the updated form
360
367
 
361
368
  #### Defined in
362
369
 
363
- [index.ts:65](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L65)
370
+ [index.ts:65](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L65)
364
371
 
365
372
  ___
366
373
 
@@ -391,6 +398,7 @@ It contains all the data and methods needed to handle the form.
391
398
  | `isFormValid` | [`IsFormValid`](#isformvalid) | Returns true id the form is valid It doesn't perform any validation, it checks if any errors are present |
392
399
  | `liveValidation` | [`LiveValidationFn`](#livevalidationfn) | Returns true if live validation is active for the given path |
393
400
  | `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. |
401
+ | `removeAll` | [`RemoveAll`](#removeall)\<`Values`\> | This method updates the form state deleting multiple values, setting isDirty to true. |
394
402
  | `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
403
  | `setError` | [`SetError`](#seterror) | Set a message(value) to the given error path. |
396
404
  | `setSchema` | [`SetSchema`](#setschema)\<`Values`\> | Override the current schema with the given one. |
@@ -403,7 +411,7 @@ It contains all the data and methods needed to handle the form.
403
411
 
404
412
  #### Defined in
405
413
 
406
- [index.ts:341](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L341)
414
+ [index.ts:348](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L348)
407
415
 
408
416
  ___
409
417
 
@@ -419,7 +427,7 @@ ___
419
427
 
420
428
  #### Defined in
421
429
 
422
- [index.ts:67](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L67)
430
+ [index.ts:67](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L67)
423
431
 
424
432
  ___
425
433
 
@@ -431,7 +439,7 @@ InitialValues used to setup formbit, used also to reset the form to the original
431
439
 
432
440
  #### Defined in
433
441
 
434
- [index.ts:77](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L77)
442
+ [index.ts:77](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L77)
435
443
 
436
444
  ___
437
445
 
@@ -463,7 +471,7 @@ Initialize the form with new initial values
463
471
 
464
472
  #### Defined in
465
473
 
466
- [index.ts:71](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L71)
474
+ [index.ts:71](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L71)
467
475
 
468
476
  ___
469
477
 
@@ -475,7 +483,7 @@ Returns true if the form is Dirty (user already interacted with the form), false
475
483
 
476
484
  #### Defined in
477
485
 
478
- [index.ts:83](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L83)
486
+ [index.ts:83](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L83)
479
487
 
480
488
  ___
481
489
 
@@ -496,7 +504,7 @@ It doesn't perform any validation, it checks if any errors are present
496
504
 
497
505
  #### Defined in
498
506
 
499
- [index.ts:89](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L89)
507
+ [index.ts:89](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L89)
500
508
 
501
509
  ___
502
510
 
@@ -517,7 +525,7 @@ It doesn't perform any validation, it checks if any errors are present
517
525
 
518
526
  #### Defined in
519
527
 
520
- [index.ts:95](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L95)
528
+ [index.ts:95](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L95)
521
529
 
522
530
  ___
523
531
 
@@ -550,7 +558,7 @@ and age is a field that is being live-validated, liveValidation object will look
550
558
 
551
559
  #### Defined in
552
560
 
553
- [index.ts:121](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L121)
561
+ [index.ts:121](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L121)
554
562
 
555
563
  ___
556
564
 
@@ -576,7 +584,7 @@ Returns true if live validation is active for the given path
576
584
 
577
585
  #### Defined in
578
586
 
579
- [index.ts:127](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L127)
587
+ [index.ts:127](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L127)
580
588
 
581
589
  ___
582
590
 
@@ -588,7 +596,7 @@ Generic object with string as keys
588
596
 
589
597
  #### Defined in
590
598
 
591
- [index.ts:133](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L133)
599
+ [index.ts:133](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L133)
592
600
 
593
601
  ___
594
602
 
@@ -624,7 +632,40 @@ and all the fields that have the live validation active.
624
632
 
625
633
  #### Defined in
626
634
 
627
- [index.ts:152](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L152)
635
+ [index.ts:152](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L152)
636
+
637
+ ___
638
+
639
+ ### RemoveAll
640
+
641
+ Ƭ **RemoveAll**\<`Values`\>: (`arr`: `string`[], `options?`: [`WriteFnOptions`](#writefnoptions)\<`Values`\>) => `void`
642
+
643
+ This method updates the form state deleting multiple values, setting isDirty to true.
644
+
645
+ #### Type parameters
646
+
647
+ | Name | Type |
648
+ | :------ | :------ |
649
+ | `Values` | extends [`InitialValues`](#initialvalues) |
650
+
651
+ #### Type declaration
652
+
653
+ ▸ (`arr`, `options?`): `void`
654
+
655
+ ##### Parameters
656
+
657
+ | Name | Type |
658
+ | :------ | :------ |
659
+ | `arr` | `string`[] |
660
+ | `options?` | [`WriteFnOptions`](#writefnoptions)\<`Values`\> |
661
+
662
+ ##### Returns
663
+
664
+ `void`
665
+
666
+ #### Defined in
667
+
668
+ [index.ts:278](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L278)
628
669
 
629
670
  ___
630
671
 
@@ -646,7 +687,7 @@ isDirty is set back to false
646
687
 
647
688
  #### Defined in
648
689
 
649
- [index.ts:160](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L160)
690
+ [index.ts:160](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L160)
650
691
 
651
692
  ___
652
693
 
@@ -673,7 +714,7 @@ Set a message(value) to the given error path.
673
714
 
674
715
  #### Defined in
675
716
 
676
- [index.ts:175](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L175)
717
+ [index.ts:175](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L175)
677
718
 
678
719
  ___
679
720
 
@@ -705,7 +746,7 @@ Override the current schema with the given one.
705
746
 
706
747
  #### Defined in
707
748
 
708
- [index.ts:181](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L181)
749
+ [index.ts:181](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L181)
709
750
 
710
751
  ___
711
752
 
@@ -740,7 +781,7 @@ otherwise it executes the errorCallback
740
781
 
741
782
  #### Defined in
742
783
 
743
- [index.ts:188](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L188)
784
+ [index.ts:188](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L188)
744
785
 
745
786
  ___
746
787
 
@@ -773,7 +814,7 @@ Success callback invoked by some formbit methods when the operation is successfu
773
814
 
774
815
  #### Defined in
775
816
 
776
- [index.ts:197](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L197)
817
+ [index.ts:197](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L197)
777
818
 
778
819
  ___
779
820
 
@@ -807,7 +848,7 @@ Success callback invoked by the check method when the operation is successful.
807
848
 
808
849
  #### Defined in
809
850
 
810
- [index.ts:203](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L203)
851
+ [index.ts:203](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L203)
811
852
 
812
853
  ___
813
854
 
@@ -842,7 +883,7 @@ Is the right place to send your data to the backend.
842
883
 
843
884
  #### Defined in
844
885
 
845
- [index.ts:211](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L211)
886
+ [index.ts:211](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L211)
846
887
 
847
888
  ___
848
889
 
@@ -876,7 +917,7 @@ live validation active.
876
917
 
877
918
  #### Defined in
878
919
 
879
- [index.ts:222](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L222)
920
+ [index.ts:222](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L222)
880
921
 
881
922
  ___
882
923
 
@@ -910,7 +951,7 @@ live validation active.
910
951
 
911
952
  #### Defined in
912
953
 
913
- [index.ts:229](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L229)
954
+ [index.ts:229](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L229)
914
955
 
915
956
  ___
916
957
 
@@ -936,7 +977,7 @@ Options object to change the behavior of the validate methods
936
977
 
937
978
  #### Defined in
938
979
 
939
- [index.ts:312](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L312)
980
+ [index.ts:319](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L319)
940
981
 
941
982
  ___
942
983
 
@@ -970,7 +1011,7 @@ This method validates the entire form and set the corresponding errors if any.
970
1011
 
971
1012
  #### Defined in
972
1013
 
973
- [index.ts:235](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L235)
1014
+ [index.ts:235](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L235)
974
1015
 
975
1016
  ___
976
1017
 
@@ -985,7 +1026,7 @@ Link to the Yup documentation [https://github.com/jquense/yup](https://github.co
985
1026
 
986
1027
  #### Defined in
987
1028
 
988
- [index.ts:249](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L249)
1029
+ [index.ts:249](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L249)
989
1030
 
990
1031
  ___
991
1032
 
@@ -1000,7 +1041,7 @@ Link to the Yup documentation [https://github.com/jquense/yup](https://github.co
1000
1041
 
1001
1042
  #### Defined in
1002
1043
 
1003
- [index.ts:325](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L325)
1044
+ [index.ts:332](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L332)
1004
1045
 
1005
1046
  ___
1006
1047
 
@@ -1010,7 +1051,7 @@ ___
1010
1051
 
1011
1052
  #### Defined in
1012
1053
 
1013
- [index.ts:240](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L240)
1054
+ [index.ts:240](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L240)
1014
1055
 
1015
1056
  ___
1016
1057
 
@@ -1031,7 +1072,7 @@ Link to the Yup documentation [https://github.com/jquense/yup](https://github.co
1031
1072
 
1032
1073
  #### Defined in
1033
1074
 
1034
- [index.ts:169](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L169)
1075
+ [index.ts:169](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L169)
1035
1076
 
1036
1077
  ___
1037
1078
 
@@ -1068,7 +1109,7 @@ and all the fields that have the live validation active.
1068
1109
 
1069
1110
  #### Defined in
1070
1111
 
1071
- [index.ts:258](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L258)
1112
+ [index.ts:258](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L258)
1072
1113
 
1073
1114
  ___
1074
1115
 
@@ -1107,7 +1148,7 @@ the fields that have the live validation active.
1107
1148
 
1108
1149
  #### Defined in
1109
1150
 
1110
- [index.ts:271](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L271)
1151
+ [index.ts:271](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L271)
1111
1152
 
1112
1153
  ___
1113
1154
 
@@ -1125,7 +1166,7 @@ Tuple of [key, value] pair.
1125
1166
 
1126
1167
  #### Defined in
1127
1168
 
1128
- [index.ts:278](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L278)
1169
+ [index.ts:285](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L285)
1129
1170
 
1130
1171
  ___
1131
1172
 
@@ -1143,7 +1184,7 @@ Options object to change the behavior of the write methods
1143
1184
 
1144
1185
  #### Defined in
1145
1186
 
1146
- [index.ts:331](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L331)
1187
+ [index.ts:338](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L338)
1147
1188
 
1148
1189
  ___
1149
1190
 
@@ -1171,7 +1212,7 @@ Internal form state storing all the data of the form (except the validation sche
1171
1212
 
1172
1213
  #### Defined in
1173
1214
 
1174
- [index.ts:290](https://github.com/radicalbit/formbit/blob/b189a1d/src/types/index.ts#L290)
1215
+ [index.ts:297](https://github.com/radicalbit/formbit/blob/a28ef40/src/types/index.ts#L297)
1175
1216
 
1176
1217
  <!-- END_TYPES_DOC -->
1177
1218
 
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};