@radicalbit/formbit 2.1.0 → 3.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.
- package/README.md +150 -400
- package/dist/__tests__/is-validation-error.test.d.ts +1 -0
- package/dist/formbit-context.d.ts +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +5 -5
- package/dist/index.modern.js.map +1 -1
- package/dist/types/index.d.ts +118 -273
- package/dist/use-execute-callbacks.d.ts +2 -2
- package/dist/use-formbit.d.ts +5 -5
- package/dist/validate-sync-all.d.ts +2 -2
- package/package.json +3 -2
package/dist/types/index.d.ts
CHANGED
|
@@ -1,333 +1,178 @@
|
|
|
1
1
|
import { ObjectSchema, ValidationError as YupValidationError, ValidateOptions as YupValidateOptions } from 'yup';
|
|
2
2
|
import { ACTIONS } from '../helpers/constants';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @internal
|
|
10
|
-
* Generic object with string keys.
|
|
11
|
-
*/
|
|
12
|
-
export type FormbitRecord = Record<string, unknown>;
|
|
13
|
-
/** @deprecated Use {@link FormbitRecord} instead. Renamed to avoid shadowing the global `Object`. */
|
|
14
|
-
export type Object = FormbitRecord;
|
|
15
|
-
/**
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
export type GenericCallback<Values extends InitialValues> = SuccessCallback<Values> | ErrorCallback<Values>;
|
|
19
|
-
/**
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
export type ValidationFormbitError = Pick<ValidationError, 'message' | 'path'>;
|
|
23
|
-
/**
|
|
24
|
-
* @internal
|
|
25
|
-
* @private
|
|
26
|
-
*/
|
|
27
|
-
export type WriteOrRemove<Values extends Form> = (path: keyof Values | string, value: unknown, options?: WriteFnOptions<Values>, action?: Action) => void;
|
|
28
|
-
/**
|
|
29
|
-
* @internal
|
|
30
|
-
* @private
|
|
31
|
-
*/
|
|
32
|
-
export type PrivateValidateForm<Values extends InitialValues> = (successCallback?: SuccessCallback<Values>, errorCallback?: ErrorCallback<Partial<Values>>, options?: {
|
|
33
|
-
options?: ValidateOptions;
|
|
34
|
-
isDirty?: boolean;
|
|
35
|
-
}) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Base type for form values: a record of string keys with an optional `__metadata` field.
|
|
4
|
+
* Base shape of every form handled by formbit: an open record of values, plus an
|
|
5
|
+
* optional `__metadata` field formbit uses to carry data that must survive a
|
|
6
|
+
* reset/initialize but must NOT be submitted.
|
|
7
|
+
*
|
|
8
|
+
* The generic `T` you pass to `useFormbit<T>()` must extend this type.
|
|
38
9
|
*/
|
|
39
|
-
export type FormbitValues = {
|
|
40
|
-
__metadata?:
|
|
41
|
-
}
|
|
42
|
-
/** Object containing the updated form. */
|
|
43
|
-
export type Form = FormbitValues;
|
|
44
|
-
/** InitialValues used to set up formbit; also used to reset the form to its original version. */
|
|
45
|
-
export type InitialValues = FormbitValues;
|
|
10
|
+
export type FormbitValues = Record<string, unknown> & {
|
|
11
|
+
__metadata?: Record<string, unknown>;
|
|
12
|
+
};
|
|
46
13
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
14
|
+
* Error messages registered since the last validation, stored under the same
|
|
15
|
+
* dot-path as the corresponding form value.
|
|
49
16
|
*
|
|
50
17
|
* @example
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* {
|
|
54
|
-
* "age": 1
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
* and age is a non valid field, errors object will look like this
|
|
58
|
-
* ```json
|
|
59
|
-
* {
|
|
60
|
-
* "age": "Age must be greater then 18"
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
18
|
+
* form: { age: 1 }
|
|
19
|
+
* errors: { age: "Age must be greater than 18" }
|
|
63
20
|
*/
|
|
64
21
|
export type Errors = Record<string, string>;
|
|
65
22
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* will automatically be set to live-validated.
|
|
69
|
-
*
|
|
70
|
-
* A value/path is live-validated when validated at every change of the form.
|
|
71
|
-
*
|
|
72
|
-
* By default no field is live-validated.
|
|
23
|
+
* Fields currently under live-validation (re-validated on every form change).
|
|
24
|
+
* A field is added here automatically when it fails a validation. Empty by default.
|
|
73
25
|
*
|
|
74
26
|
* @example
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* {
|
|
78
|
-
* "age": 1
|
|
79
|
-
* }
|
|
80
|
-
* ```
|
|
81
|
-
* and age is a field that is being live-validated, liveValidation object will look like this
|
|
82
|
-
* ```json
|
|
83
|
-
* {
|
|
84
|
-
* "age": true
|
|
85
|
-
* }
|
|
86
|
-
* ```
|
|
27
|
+
* form: { age: 1 }
|
|
28
|
+
* liveValidation: { age: true }
|
|
87
29
|
*/
|
|
88
30
|
export type LiveValidation = Record<string, true>;
|
|
89
31
|
/**
|
|
90
|
-
*
|
|
32
|
+
* The whole internal state of the form (everything except the validation schema).
|
|
91
33
|
*/
|
|
92
|
-
export type FormState<
|
|
93
|
-
form:
|
|
94
|
-
initialValues:
|
|
34
|
+
export type FormState<T extends FormbitValues> = {
|
|
35
|
+
form: T;
|
|
36
|
+
initialValues: T;
|
|
95
37
|
errors: Errors;
|
|
96
38
|
liveValidation: LiveValidation;
|
|
97
39
|
isDirty: boolean;
|
|
98
40
|
};
|
|
99
|
-
/**
|
|
100
|
-
export type
|
|
101
|
-
/**
|
|
102
|
-
* Type imported from the yup library.
|
|
103
|
-
* It represents any validation schema created with the yup.object() method.
|
|
104
|
-
*
|
|
105
|
-
* Link to the Yup documentation {@link https://github.com/jquense/yup}
|
|
106
|
-
*/
|
|
107
|
-
export type ValidationSchema<Values extends InitialValues> = ObjectSchema<Values>;
|
|
108
|
-
/**
|
|
109
|
-
* Type imported from the yup library.
|
|
110
|
-
* It represents the object with all the options that can be passed to the internal yup validation method.
|
|
111
|
-
*
|
|
112
|
-
* Link to the Yup documentation {@link https://github.com/jquense/yup}
|
|
113
|
-
*/
|
|
41
|
+
/** A validation schema built with `yup.object()`. See {@link https://github.com/jquense/yup}. */
|
|
42
|
+
export type ValidationSchema<T extends FormbitValues> = ObjectSchema<T>;
|
|
43
|
+
/** Options forwarded to yup's validation methods. See {@link https://github.com/jquense/yup}. */
|
|
114
44
|
export type ValidateOptions = YupValidateOptions;
|
|
115
|
-
/**
|
|
116
|
-
* Type imported from the yup library.
|
|
117
|
-
* It represents the error object returned when a validation fails.
|
|
118
|
-
*
|
|
119
|
-
* Link to the Yup documentation {@link https://github.com/jquense/yup}
|
|
120
|
-
*/
|
|
45
|
+
/** The error object yup throws when a validation fails. See {@link https://github.com/jquense/yup}. */
|
|
121
46
|
export type ValidationError = YupValidationError;
|
|
122
|
-
/**
|
|
123
|
-
|
|
124
|
-
*/
|
|
125
|
-
export type
|
|
126
|
-
/**
|
|
127
|
-
|
|
128
|
-
*/
|
|
129
|
-
export type
|
|
130
|
-
/**
|
|
131
|
-
*
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
export type SuccessCheckCallback<Values extends InitialValues> = CheckSuccessCallback<Values>;
|
|
136
|
-
/**
|
|
137
|
-
* Invoked in case of errors raised by validation of check method.
|
|
138
|
-
*/
|
|
139
|
-
export type CheckErrorCallback<Values extends InitialValues> = (json: Form, inner: ValidationError[], writer: FormState<Values>, setError: SetError) => void;
|
|
140
|
-
/** @deprecated Use {@link CheckErrorCallback} instead. */
|
|
141
|
-
export type ErrorCheckCallback<Values extends InitialValues> = CheckErrorCallback<Values>;
|
|
142
|
-
/**
|
|
143
|
-
* Success callback invoked by the submit method when the validation is successful.
|
|
144
|
-
* Is the right place to send your data to the backend.
|
|
145
|
-
*/
|
|
146
|
-
export type SubmitSuccessCallback<Values extends InitialValues> = (writer: FormState<Values | Omit<Values, '__metadata'>>, setError: SetError, clearIsDirty: () => void) => void;
|
|
147
|
-
/** @deprecated Inlined into {@link FormbitObject}. */
|
|
148
|
-
export type ErrorFn = (path: string) => string | undefined;
|
|
149
|
-
/** @deprecated Inlined into {@link FormbitObject}. */
|
|
150
|
-
export type IsFormValid = () => boolean;
|
|
151
|
-
/** @deprecated Inlined into {@link FormbitObject}. */
|
|
152
|
-
export type IsFormInvalid = () => boolean;
|
|
153
|
-
/** @deprecated Inlined into {@link FormbitObject}. */
|
|
154
|
-
export type ClearIsDirty = () => void;
|
|
155
|
-
/** @deprecated Inlined into {@link FormbitObject}. */
|
|
156
|
-
export type ResetForm = () => void;
|
|
157
|
-
/** @deprecated Inlined into {@link FormbitObject}. */
|
|
158
|
-
export type LiveValidationFn = (path: string) => true | undefined;
|
|
159
|
-
/** @deprecated Inlined into {@link FormbitObject}. */
|
|
160
|
-
export type IsDirty = boolean;
|
|
47
|
+
/** Invoked by validation methods when the form (or the validated paths) are valid. */
|
|
48
|
+
export type SuccessCallback<T extends FormbitValues> = (writer: FormState<T>, setError: SetError) => void;
|
|
49
|
+
/** Invoked by validation methods when validation fails. */
|
|
50
|
+
export type ErrorCallback<T extends FormbitValues> = (writer: FormState<T>, setError: SetError) => void;
|
|
51
|
+
/** Invoked by `check()` when the given json is valid. */
|
|
52
|
+
export type CheckSuccessCallback<T extends FormbitValues> = (json: FormbitValues, writer: FormState<T>, setError: SetError) => void;
|
|
53
|
+
/** Invoked by `check()` when the given json is invalid. */
|
|
54
|
+
export type CheckErrorCallback<T extends FormbitValues> = (json: FormbitValues, inner: ValidationError[], writer: FormState<T>, setError: SetError) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Invoked by `submitForm()` once the whole form is valid — the place to send data
|
|
57
|
+
* to the backend. `__metadata` is stripped from `writer.form` before this runs.
|
|
58
|
+
*/
|
|
59
|
+
export type SubmitSuccessCallback<T extends FormbitValues> = (writer: FormState<Omit<T, '__metadata'>>, setError: SetError, clearIsDirty: () => void) => void;
|
|
161
60
|
/** See {@link FormbitObject.check}. */
|
|
162
|
-
export type Check<
|
|
61
|
+
export type Check<T extends FormbitValues> = (json: FormbitValues, options?: CheckFnOptions<T>) => ValidationError[] | undefined;
|
|
163
62
|
/** See {@link FormbitObject.initialize}. */
|
|
164
|
-
export type Initialize<
|
|
63
|
+
export type Initialize<T extends FormbitValues> = (values: Partial<T>) => void;
|
|
165
64
|
/** See {@link FormbitObject.remove}. */
|
|
166
|
-
export type Remove<
|
|
65
|
+
export type Remove<T extends FormbitValues> = (path: string, options?: WriteFnOptions<T>) => void;
|
|
167
66
|
/** See {@link FormbitObject.setError}. */
|
|
168
67
|
export type SetError = (path: string, value: string) => void;
|
|
169
68
|
/** See {@link FormbitObject.setSchema}. */
|
|
170
|
-
export type SetSchema<
|
|
171
|
-
/**
|
|
172
|
-
export type
|
|
173
|
-
/** See {@link FormbitObject.validate}. */
|
|
174
|
-
export type Validate<Values extends InitialValues> = (path: string, options?: ValidateFnOptions<Values>) => void;
|
|
175
|
-
/** See {@link FormbitObject.validateAll}. */
|
|
176
|
-
export type ValidateAll<Values extends InitialValues> = (paths: string[], options?: ValidateFnOptions<Values>) => void;
|
|
177
|
-
/** See {@link FormbitObject.validateForm}. */
|
|
178
|
-
export type ValidateForm<Values extends InitialValues> = (successCallback?: SuccessCallback<Values>, errorCallback?: ErrorCallback<Values>, options?: ValidateOptions) => void;
|
|
69
|
+
export type SetSchema<T extends FormbitValues> = (newSchema: ValidationSchema<T>) => void;
|
|
70
|
+
/** A single `[path, value]` pair accepted by `writeAll`. */
|
|
71
|
+
export type WriteAllValue<T extends FormbitValues> = [keyof T | string, unknown];
|
|
179
72
|
/** See {@link FormbitObject.write}. */
|
|
180
|
-
export type Write<
|
|
73
|
+
export type Write<T extends FormbitValues> = (path: keyof T | string, value: unknown, options?: WriteFnOptions<T>) => void;
|
|
181
74
|
/** See {@link FormbitObject.writeAll}. */
|
|
182
|
-
export type WriteAll<
|
|
75
|
+
export type WriteAll<T extends FormbitValues> = (arr: WriteAllValue<T>[], options?: WriteFnOptions<T>) => void;
|
|
183
76
|
/** See {@link FormbitObject.removeAll}. */
|
|
184
|
-
export type RemoveAll<
|
|
185
|
-
/**
|
|
186
|
-
|
|
187
|
-
*/
|
|
188
|
-
export type
|
|
189
|
-
/**
|
|
190
|
-
|
|
191
|
-
*/
|
|
192
|
-
export type
|
|
193
|
-
|
|
194
|
-
|
|
77
|
+
export type RemoveAll<T extends FormbitValues> = (arr: string[], options?: WriteFnOptions<T>) => void;
|
|
78
|
+
/** See {@link FormbitObject.validate}. */
|
|
79
|
+
export type Validate<T extends FormbitValues> = (path: string, options?: ValidateFnOptions<T>) => void;
|
|
80
|
+
/** See {@link FormbitObject.validateAll}. */
|
|
81
|
+
export type ValidateAll<T extends FormbitValues> = (paths: string[], options?: ValidateFnOptions<T>) => void;
|
|
82
|
+
/** See {@link FormbitObject.validateForm}. */
|
|
83
|
+
export type ValidateForm<T extends FormbitValues> = (successCallback?: SuccessCallback<T>, errorCallback?: ErrorCallback<T>, options?: ValidateOptions) => void;
|
|
84
|
+
/** See {@link FormbitObject.submitForm}. */
|
|
85
|
+
export type SubmitForm<T extends FormbitValues> = (successCallback: SubmitSuccessCallback<T>, errorCallback?: ErrorCallback<Partial<T>>, options?: ValidateOptions) => void;
|
|
86
|
+
/** Options accepted by `check()`. */
|
|
87
|
+
export type CheckFnOptions<T extends FormbitValues> = {
|
|
88
|
+
successCallback?: CheckSuccessCallback<T>;
|
|
89
|
+
errorCallback?: CheckErrorCallback<T>;
|
|
195
90
|
options?: ValidateOptions;
|
|
196
91
|
};
|
|
197
|
-
/**
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
successCallback?: SuccessCallback<Partial<Values>>;
|
|
202
|
-
errorCallback?: ErrorCallback<Partial<Values>>;
|
|
92
|
+
/** Options accepted by the `validate` methods. */
|
|
93
|
+
export type ValidateFnOptions<T extends FormbitValues> = {
|
|
94
|
+
successCallback?: SuccessCallback<Partial<T>>;
|
|
95
|
+
errorCallback?: ErrorCallback<Partial<T>>;
|
|
203
96
|
options?: ValidateOptions;
|
|
204
97
|
};
|
|
205
|
-
/**
|
|
206
|
-
|
|
207
|
-
*/
|
|
208
|
-
export type WriteFnOptions<Values extends InitialValues> = {
|
|
98
|
+
/** Options accepted by the `write`/`remove` methods (validate options plus path control). */
|
|
99
|
+
export type WriteFnOptions<T extends FormbitValues> = {
|
|
209
100
|
noLiveValidation?: boolean;
|
|
210
101
|
pathsToValidate?: string[];
|
|
211
|
-
} & ValidateFnOptions<
|
|
102
|
+
} & ValidateFnOptions<T>;
|
|
103
|
+
/** @internal */
|
|
104
|
+
export type Action = keyof typeof ACTIONS;
|
|
105
|
+
/** @internal */
|
|
106
|
+
export type GenericCallback<T extends FormbitValues> = SuccessCallback<T> | ErrorCallback<T>;
|
|
107
|
+
/** @internal Subset of a yup ValidationError kept by formbit's sync validation. */
|
|
108
|
+
export type ValidationFormbitError = Pick<ValidationError, 'message' | 'path'>;
|
|
109
|
+
/** @internal */
|
|
110
|
+
export type WriteOrRemove<T extends FormbitValues> = (path: keyof T | string, value: unknown, options?: WriteFnOptions<T>, action?: Action) => void;
|
|
111
|
+
/** @internal */
|
|
112
|
+
export type PrivateValidateForm<T extends FormbitValues> = (successCallback?: SuccessCallback<T>, errorCallback?: ErrorCallback<Partial<T>>, options?: {
|
|
113
|
+
options?: ValidateOptions;
|
|
114
|
+
}) => void;
|
|
212
115
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
116
|
+
* The object returned by `useFormbit()` and `useFormbitContext()`. Holds the form
|
|
117
|
+
* state and every method needed to read, mutate and validate the form.
|
|
215
118
|
*/
|
|
216
|
-
export type FormbitObject<
|
|
119
|
+
export type FormbitObject<T extends FormbitValues> = {
|
|
120
|
+
/** The current form values. Partial: fields may be missing until validated. */
|
|
121
|
+
form: Partial<T>;
|
|
217
122
|
/**
|
|
218
|
-
*
|
|
219
|
-
*/
|
|
220
|
-
form: Partial<Values>;
|
|
221
|
-
/**
|
|
222
|
-
* Object including all the registered error messages since the last validation.
|
|
223
|
-
* Errors are stored using the same path of the corresponding form values.
|
|
123
|
+
* Error messages registered since the last validation, keyed by the value's dot-path.
|
|
224
124
|
*
|
|
225
125
|
* @example
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
* {
|
|
229
|
-
* "age": 1
|
|
230
|
-
* }
|
|
231
|
-
* ```
|
|
232
|
-
* and age is a non valid field, errors object will look like this
|
|
233
|
-
* ```json
|
|
234
|
-
* {
|
|
235
|
-
* "age": "Age must be greater then 18"
|
|
236
|
-
* }
|
|
237
|
-
* ```
|
|
126
|
+
* form: { age: 1 }
|
|
127
|
+
* errors: { age: "Age must be greater than 18" }
|
|
238
128
|
*/
|
|
239
129
|
errors: Errors;
|
|
240
|
-
/**
|
|
241
|
-
* Returns true if the form is Dirty (user already interacted with the form), false otherwise.
|
|
242
|
-
*/
|
|
130
|
+
/** True once the user has interacted with the form. */
|
|
243
131
|
isDirty: boolean;
|
|
244
|
-
/**
|
|
245
|
-
* Returns the error message for the given path if any.
|
|
246
|
-
* It doesn't trigger any validation.
|
|
247
|
-
*/
|
|
132
|
+
/** Returns the error message registered for `path`, if any. */
|
|
248
133
|
error: (path: string) => string | undefined;
|
|
249
|
-
/**
|
|
250
|
-
* Returns true if the form is valid.
|
|
251
|
-
* It doesn't perform any validation, it checks if any errors are present.
|
|
252
|
-
*/
|
|
134
|
+
/** True if no errors are currently registered. Does not run validation. */
|
|
253
135
|
isFormValid: () => boolean;
|
|
254
|
-
/**
|
|
255
|
-
* Returns true if the form is NOT valid.
|
|
256
|
-
* It doesn't perform any validation, it checks if any errors are present.
|
|
257
|
-
*/
|
|
136
|
+
/** True if any error is currently registered. Does not run validation. */
|
|
258
137
|
isFormInvalid: () => boolean;
|
|
259
|
-
/**
|
|
260
|
-
* Returns true if live validation is active for the given path.
|
|
261
|
-
*/
|
|
138
|
+
/** True if live-validation is active for `path`. */
|
|
262
139
|
liveValidation: (path: string) => true | undefined;
|
|
140
|
+
/** Validates `json` against the current schema; returns the errors, or undefined if valid. */
|
|
141
|
+
check: Check<Partial<T>>;
|
|
263
142
|
/**
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*/
|
|
267
|
-
check: Check<Partial<Values>>;
|
|
268
|
-
/**
|
|
269
|
-
* This method updates the form state writing $value into the $path, setting isDirty to true.
|
|
270
|
-
*
|
|
271
|
-
* After writing, it validates all the paths contained into $pathsToValidate (if any)
|
|
272
|
-
* and all the fields that have the live validation active.
|
|
273
|
-
*/
|
|
274
|
-
write: Write<Values>;
|
|
275
|
-
/**
|
|
276
|
-
* This method takes an array of [path, value] and updates the form state writing
|
|
277
|
-
* all those values into the specified paths.
|
|
278
|
-
*
|
|
279
|
-
* It sets isDirty to true.
|
|
280
|
-
*
|
|
281
|
-
* After writing, it validates all the paths contained into $pathToValidate and all
|
|
282
|
-
* the fields that have the live validation active.
|
|
283
|
-
*/
|
|
284
|
-
writeAll: WriteAll<Values>;
|
|
285
|
-
/**
|
|
286
|
-
* This method updates the form state deleting value, setting isDirty to true.
|
|
287
|
-
*
|
|
288
|
-
* After writing, it validates all the paths contained into pathsToValidate (if any)
|
|
289
|
-
* and all the fields that have the live validation active.
|
|
143
|
+
* Writes `value` at `path`, sets `isDirty`, then validates `pathsToValidate`
|
|
144
|
+
* plus every live-validated field.
|
|
290
145
|
*/
|
|
291
|
-
|
|
146
|
+
write: Write<T>;
|
|
292
147
|
/**
|
|
293
|
-
*
|
|
148
|
+
* Writes every `[path, value]` pair, sets `isDirty`, then validates
|
|
149
|
+
* `pathsToValidate` plus every live-validated field.
|
|
294
150
|
*/
|
|
295
|
-
|
|
151
|
+
writeAll: WriteAll<T>;
|
|
296
152
|
/**
|
|
297
|
-
*
|
|
153
|
+
* Removes the value at `path`, sets `isDirty`, then validates `pathsToValidate`
|
|
154
|
+
* plus every live-validated field.
|
|
298
155
|
*/
|
|
299
|
-
|
|
156
|
+
remove: Remove<T>;
|
|
300
157
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* isDirty is set back to false.
|
|
158
|
+
* Removes every given path, sets `isDirty`, then validates `pathsToValidate`
|
|
159
|
+
* plus every live-validated field.
|
|
304
160
|
*/
|
|
161
|
+
removeAll: RemoveAll<T>;
|
|
162
|
+
/** Re-initializes the form with new initial values. */
|
|
163
|
+
initialize: Initialize<T>;
|
|
164
|
+
/** Resets form, errors, liveValidation and isDirty back to their initial state. */
|
|
305
165
|
resetForm: () => void;
|
|
306
|
-
/**
|
|
307
|
-
* Set a message (value) to the given error path.
|
|
308
|
-
*/
|
|
166
|
+
/** Sets the error message at `path`. */
|
|
309
167
|
setError: SetError;
|
|
310
|
-
/**
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
* This method only validates the specified paths. Does not check for fields that have the
|
|
321
|
-
* live validation active.
|
|
322
|
-
*/
|
|
323
|
-
validateAll: ValidateAll<Values>;
|
|
324
|
-
/**
|
|
325
|
-
* This method validates the entire form and sets the corresponding errors if any.
|
|
326
|
-
*/
|
|
327
|
-
validateForm: ValidateForm<Partial<Values>>;
|
|
328
|
-
/**
|
|
329
|
-
* Perform a validation against the current form object, and execute the successCallback if the validation passes,
|
|
330
|
-
* otherwise it executes the errorCallback.
|
|
331
|
-
*/
|
|
332
|
-
submitForm: SubmitForm<Values>;
|
|
168
|
+
/** Replaces the current validation schema. */
|
|
169
|
+
setSchema: SetSchema<T>;
|
|
170
|
+
/** Validates only `path` (ignores live-validated fields). */
|
|
171
|
+
validate: Validate<T>;
|
|
172
|
+
/** Validates only the given `paths` (ignores live-validated fields). */
|
|
173
|
+
validateAll: ValidateAll<T>;
|
|
174
|
+
/** Validates the whole form and registers any error. */
|
|
175
|
+
validateForm: ValidateForm<Partial<T>>;
|
|
176
|
+
/** Validates the whole form and, if valid, runs the success callback to submit. */
|
|
177
|
+
submitForm: SubmitForm<T>;
|
|
333
178
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormState, GenericCallback, SetError } from './types';
|
|
1
|
+
import { FormState, GenericCallback, FormbitValues, SetError } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* useExecuteCallbacks
|
|
4
4
|
*
|
|
@@ -7,5 +7,5 @@ import { FormState, GenericCallback, SetError } from './types';
|
|
|
7
7
|
*
|
|
8
8
|
*
|
|
9
9
|
*/
|
|
10
|
-
declare const _default: <
|
|
10
|
+
declare const _default: <T extends FormbitValues>(writer: FormState<T>, setError: SetError) => (uuid: string, cb?: GenericCallback<Partial<T>>) => void;
|
|
11
11
|
export default _default;
|
package/dist/use-formbit.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { FormbitObject,
|
|
2
|
-
type UseFormbitParams<
|
|
3
|
-
initialValues?: Partial<
|
|
4
|
-
yup: ValidationSchema<
|
|
1
|
+
import { FormbitObject, FormbitValues, ValidationSchema } from './types';
|
|
2
|
+
type UseFormbitParams<T extends FormbitValues> = {
|
|
3
|
+
initialValues?: Partial<T>;
|
|
4
|
+
yup: ValidationSchema<T>;
|
|
5
5
|
};
|
|
6
|
-
declare const _default: <
|
|
6
|
+
declare const _default: <T extends FormbitValues>({ initialValues, yup: schema }: UseFormbitParams<T>) => FormbitObject<T>;
|
|
7
7
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const validateSyncAll: <
|
|
1
|
+
import { FormbitValues, ValidateOptions, ValidationFormbitError, ValidationSchema } from './types';
|
|
2
|
+
export declare const validateSyncAll: <T extends FormbitValues>(paths: string[], schema: ValidationSchema<T>, form: FormbitValues, options?: ValidateOptions) => ValidationFormbitError[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radicalbit/formbit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Lightweight state form library",
|
|
5
5
|
"author": "https://github.com/radicalbit",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,11 +51,12 @@
|
|
|
51
51
|
"@typescript-eslint/parser": "^7.4.0",
|
|
52
52
|
"cross-env": "^7.0.2",
|
|
53
53
|
"doctoc": "^2.2.1",
|
|
54
|
-
"eslint": "
|
|
54
|
+
"eslint": "8.57.0",
|
|
55
55
|
"eslint-config-prettier": "^9.1.0",
|
|
56
56
|
"eslint-config-react-app": "^7.0.1",
|
|
57
57
|
"eslint-config-standard": "^17.1.0",
|
|
58
58
|
"eslint-config-standard-react": "^13.0.0",
|
|
59
|
+
"eslint-plugin-cypress": "^2.15.0",
|
|
59
60
|
"eslint-plugin-import": "^2.29.1",
|
|
60
61
|
"eslint-plugin-jest": "^27.9.0",
|
|
61
62
|
"eslint-plugin-n": "^16.6.2",
|