@railway-ts/use-form 0.1.26 → 0.1.28
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 +11 -37
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +46 -164
- package/dist/index.mjs.map +1 -1
- package/docs/API.md +39 -40
- package/docs/GETTING_STARTED.md +34 -84
- package/docs/RECIPES.md +65 -248
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -32,21 +32,13 @@ Bring your own Zod, Valibot, or ArkType via [Standard Schema](https://github.com
|
|
|
32
32
|
bun add @railway-ts/use-form @railway-ts/pipelines # or npm, pnpm, yarn
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
Requires React 18+ and @railway-ts/pipelines ^0.1.
|
|
35
|
+
Requires React 18+ and @railway-ts/pipelines ^0.1.27.
|
|
36
36
|
|
|
37
37
|
## Quick Start
|
|
38
38
|
|
|
39
39
|
```tsx
|
|
40
40
|
import { useForm } from '@railway-ts/use-form';
|
|
41
|
-
import {
|
|
42
|
-
object,
|
|
43
|
-
string,
|
|
44
|
-
required,
|
|
45
|
-
chain,
|
|
46
|
-
nonEmpty,
|
|
47
|
-
email,
|
|
48
|
-
type InferSchemaType,
|
|
49
|
-
} from '@railway-ts/pipelines/schema';
|
|
41
|
+
import { object, string, required, chain, nonEmpty, email, type InferSchemaType } from '@railway-ts/pipelines/schema';
|
|
50
42
|
|
|
51
43
|
const loginSchema = object({
|
|
52
44
|
email: required(chain(string(), nonEmpty('Email is required'), email())),
|
|
@@ -66,14 +58,10 @@ export function LoginForm() {
|
|
|
66
58
|
return (
|
|
67
59
|
<form onSubmit={(e) => void form.handleSubmit(e)}>
|
|
68
60
|
<input type="email" {...form.getFieldProps('email')} />
|
|
69
|
-
{form.getFieldError('email') && (
|
|
70
|
-
<span>{form.getFieldError('email')}</span>
|
|
71
|
-
)}
|
|
61
|
+
{form.getFieldError('email') && <span>{form.getFieldError('email')}</span>}
|
|
72
62
|
|
|
73
63
|
<input type="password" {...form.getFieldProps('password')} />
|
|
74
|
-
{form.getFieldError('password') && (
|
|
75
|
-
<span>{form.getFieldError('password')}</span>
|
|
76
|
-
)}
|
|
64
|
+
{form.getFieldError('password') && <span>{form.getFieldError('password')}</span>}
|
|
77
65
|
|
|
78
66
|
<button type="submit" disabled={form.isSubmitting}>
|
|
79
67
|
{form.isSubmitting ? 'Logging in...' : 'Log In'}
|
|
@@ -113,11 +101,7 @@ const schema = chain(
|
|
|
113
101
|
password: required(chain(string(), nonEmpty(), minLength(8))),
|
|
114
102
|
confirmPassword: required(chain(string(), nonEmpty())),
|
|
115
103
|
}),
|
|
116
|
-
refineAt(
|
|
117
|
-
'confirmPassword',
|
|
118
|
-
(d) => d.password === d.confirmPassword,
|
|
119
|
-
'Passwords must match'
|
|
120
|
-
)
|
|
104
|
+
refineAt('confirmPassword', (d) => d.password === d.confirmPassword, 'Passwords must match'),
|
|
121
105
|
);
|
|
122
106
|
|
|
123
107
|
type Registration = InferSchemaType<typeof schema>;
|
|
@@ -126,7 +110,7 @@ type Registration = InferSchemaType<typeof schema>;
|
|
|
126
110
|
|
|
127
111
|
const checkUsername = (username: string): Promise<{ available: boolean }> =>
|
|
128
112
|
fetch(`/api/check-username?u=${encodeURIComponent(username)}`).then((res) =>
|
|
129
|
-
res.ok ? res.json() : Promise.reject(`HTTP ${res.status}`)
|
|
113
|
+
res.ok ? res.json() : Promise.reject(`HTTP ${res.status}`),
|
|
130
114
|
);
|
|
131
115
|
|
|
132
116
|
class ApiValidationError extends Error {
|
|
@@ -193,28 +177,18 @@ export function RegistrationForm() {
|
|
|
193
177
|
<form onSubmit={(e) => void form.handleSubmit(e)}>
|
|
194
178
|
<input {...form.getFieldProps('username')} />
|
|
195
179
|
{form.validatingFields.username && <span>Checking...</span>}
|
|
196
|
-
{form.getFieldError('username') && (
|
|
197
|
-
<span>{form.getFieldError('username')}</span>
|
|
198
|
-
)}
|
|
180
|
+
{form.getFieldError('username') && <span>{form.getFieldError('username')}</span>}
|
|
199
181
|
|
|
200
182
|
<input type="email" {...form.getFieldProps('email')} />
|
|
201
|
-
{form.getFieldError('email') && (
|
|
202
|
-
<span>{form.getFieldError('email')}</span>
|
|
203
|
-
)}
|
|
183
|
+
{form.getFieldError('email') && <span>{form.getFieldError('email')}</span>}
|
|
204
184
|
|
|
205
185
|
<input type="password" {...form.getFieldProps('password')} />
|
|
206
|
-
{form.getFieldError('password') && (
|
|
207
|
-
<span>{form.getFieldError('password')}</span>
|
|
208
|
-
)}
|
|
186
|
+
{form.getFieldError('password') && <span>{form.getFieldError('password')}</span>}
|
|
209
187
|
|
|
210
188
|
<input type="password" {...form.getFieldProps('confirmPassword')} />
|
|
211
|
-
{form.getFieldError('confirmPassword') && (
|
|
212
|
-
<span>{form.getFieldError('confirmPassword')}</span>
|
|
213
|
-
)}
|
|
189
|
+
{form.getFieldError('confirmPassword') && <span>{form.getFieldError('confirmPassword')}</span>}
|
|
214
190
|
|
|
215
|
-
{form.errors[ROOT_ERROR_KEY] &&
|
|
216
|
-
<span>{form.errors[ROOT_ERROR_KEY]}</span>
|
|
217
|
-
)}
|
|
191
|
+
{form.errors[ROOT_ERROR_KEY] && <span>{form.errors[ROOT_ERROR_KEY]}</span>}
|
|
218
192
|
|
|
219
193
|
<button type="submit" disabled={mutation.isPending || form.isValidating}>
|
|
220
194
|
{mutation.isPending ? 'Registering...' : 'Create Account'}
|
package/dist/index.d.ts
CHANGED
|
@@ -454,8 +454,10 @@ type NativeCheckboxGroupOptionProps = {
|
|
|
454
454
|
* type Zip = FieldTypeAtPath<User, "address.zip">; // number
|
|
455
455
|
*/
|
|
456
456
|
type FieldTypeAtPath<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? FieldTypeAtPath<NonNullable<T[K]>, Rest> : unknown : P extends keyof T ? T[P] : unknown;
|
|
457
|
+
type IsTuple<T extends readonly unknown[]> = number extends T['length'] ? false : true;
|
|
458
|
+
type TupleIndexPaths<T extends readonly unknown[]> = `${Extract<keyof T, number>}`;
|
|
457
459
|
type ExtractFieldPaths<T> = T extends readonly unknown[] ? never : T extends object ? {
|
|
458
|
-
[K in keyof T]-?: K extends string | number ? NonNullable<T[K]> extends Date |
|
|
460
|
+
[K in keyof T]-?: K extends string | number ? NonNullable<T[K]> extends Date | ((...args: never[]) => unknown) ? `${K}` : NonNullable<T[K]> extends readonly unknown[] ? IsTuple<NonNullable<T[K]>> extends true ? `${K}` | `${K}.${TupleIndexPaths<NonNullable<T[K]>>}` : `${K}` : T[K] extends object | undefined ? T[K] extends {
|
|
459
461
|
type: string;
|
|
460
462
|
} ? T[K] extends infer U ? U extends {
|
|
461
463
|
type: infer Type;
|
package/dist/index.mjs
CHANGED
|
@@ -103,10 +103,8 @@ var deepMerge = (target, source) => {
|
|
|
103
103
|
};
|
|
104
104
|
var deepEqual = (a, b) => {
|
|
105
105
|
if (Object.is(a, b)) return true;
|
|
106
|
-
if (a instanceof Date && b instanceof Date)
|
|
107
|
-
|
|
108
|
-
if (a instanceof RegExp && b instanceof RegExp)
|
|
109
|
-
return a.toString() === b.toString();
|
|
106
|
+
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
|
107
|
+
if (a instanceof RegExp && b instanceof RegExp) return a.toString() === b.toString();
|
|
110
108
|
if (a == null || b == null) return false;
|
|
111
109
|
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
112
110
|
if (Array.isArray(a)) {
|
|
@@ -117,10 +115,7 @@ var deepEqual = (a, b) => {
|
|
|
117
115
|
const keysB = Object.keys(b);
|
|
118
116
|
if (keysA.length !== keysB.length) return false;
|
|
119
117
|
return keysA.every(
|
|
120
|
-
(key) => Object.prototype.hasOwnProperty.call(b, key) && deepEqual(
|
|
121
|
-
a[key],
|
|
122
|
-
b[key]
|
|
123
|
-
)
|
|
118
|
+
(key) => Object.prototype.hasOwnProperty.call(b, key) && deepEqual(a[key], b[key])
|
|
124
119
|
);
|
|
125
120
|
};
|
|
126
121
|
|
|
@@ -128,13 +123,8 @@ var deepEqual = (a, b) => {
|
|
|
128
123
|
var formReducer = (state, action, initialValues) => {
|
|
129
124
|
switch (action.type) {
|
|
130
125
|
case "SET_FIELD_VALUE": {
|
|
131
|
-
if (getValueByPath(state.values, action.field) === action.value)
|
|
132
|
-
|
|
133
|
-
const newValues = setValueByPath(
|
|
134
|
-
state.values,
|
|
135
|
-
action.field,
|
|
136
|
-
action.value
|
|
137
|
-
);
|
|
126
|
+
if (getValueByPath(state.values, action.field) === action.value) return state;
|
|
127
|
+
const newValues = setValueByPath(state.values, action.field, action.value);
|
|
138
128
|
const newServerErrors = { ...state.serverErrors };
|
|
139
129
|
Object.keys(newServerErrors).forEach((errorPath) => {
|
|
140
130
|
if (isPathAffected(errorPath, action.field)) {
|
|
@@ -263,9 +253,7 @@ function isStandardSchema(value) {
|
|
|
263
253
|
}
|
|
264
254
|
function convertPath(path) {
|
|
265
255
|
if (!path) return [];
|
|
266
|
-
return path.map(
|
|
267
|
-
(s) => typeof s === "object" && s !== null && "key" in s ? String(s.key) : String(s)
|
|
268
|
-
);
|
|
256
|
+
return path.map((s) => typeof s === "object" && s !== null && "key" in s ? String(s.key) : String(s));
|
|
269
257
|
}
|
|
270
258
|
function convertResult(result) {
|
|
271
259
|
if ("issues" in result && result.issues) {
|
|
@@ -659,14 +647,7 @@ var createRadioGroupOptionProps = (field, optionValue, formValues, handleChange,
|
|
|
659
647
|
|
|
660
648
|
// src/useForm.ts
|
|
661
649
|
var useForm = (validatorOrSchema, options) => {
|
|
662
|
-
const {
|
|
663
|
-
initialValues,
|
|
664
|
-
onSubmit,
|
|
665
|
-
validationMode,
|
|
666
|
-
fieldValidators,
|
|
667
|
-
onValuesChange,
|
|
668
|
-
onFieldChange
|
|
669
|
-
} = options;
|
|
650
|
+
const { initialValues, onSubmit, validationMode, fieldValidators, onValuesChange, onFieldChange } = options;
|
|
670
651
|
const validator = useMemo(
|
|
671
652
|
() => isStandardSchema(validatorOrSchema) ? fromStandardSchema(validatorOrSchema) : validatorOrSchema,
|
|
672
653
|
[validatorOrSchema]
|
|
@@ -732,22 +713,19 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
732
713
|
() => formState.isFormValidating || Object.keys(formState.validatingFields).length > 0,
|
|
733
714
|
[formState.isFormValidating, formState.validatingFields]
|
|
734
715
|
);
|
|
735
|
-
const dispatchValidationResult = useCallback(
|
|
736
|
-
(result)
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
},
|
|
749
|
-
[]
|
|
750
|
-
);
|
|
716
|
+
const dispatchValidationResult = useCallback((result) => {
|
|
717
|
+
if (isErr(result)) {
|
|
718
|
+
dispatch({
|
|
719
|
+
type: "SET_CLIENT_ERRORS",
|
|
720
|
+
errors: formatErrors(result.error)
|
|
721
|
+
});
|
|
722
|
+
} else {
|
|
723
|
+
dispatch({
|
|
724
|
+
type: "SET_CLIENT_ERRORS",
|
|
725
|
+
errors: {}
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
}, []);
|
|
751
729
|
const validateForm = useCallback(
|
|
752
730
|
(values) => {
|
|
753
731
|
const validationResult = validate(values, validator);
|
|
@@ -799,9 +777,7 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
799
777
|
const runValidationPipeline = useCallback(
|
|
800
778
|
(field, values) => {
|
|
801
779
|
const currentErrors = formStateRef.current.clientErrors;
|
|
802
|
-
const hasStale = Object.keys(currentErrors).some(
|
|
803
|
-
(p) => isPathAffected(p, field)
|
|
804
|
-
);
|
|
780
|
+
const hasStale = Object.keys(currentErrors).some((p) => isPathAffected(p, field));
|
|
805
781
|
if (hasStale) {
|
|
806
782
|
const cleaned = { ...currentErrors };
|
|
807
783
|
Object.keys(cleaned).forEach((p) => {
|
|
@@ -838,9 +814,7 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
838
814
|
if (validateOnMount && !didMountRef.current) {
|
|
839
815
|
didMountRef.current = true;
|
|
840
816
|
void validateForm(initialValues);
|
|
841
|
-
const allFields = collectFieldPaths(
|
|
842
|
-
initialValues
|
|
843
|
-
);
|
|
817
|
+
const allFields = collectFieldPaths(initialValues);
|
|
844
818
|
dispatch({
|
|
845
819
|
type: "MARK_ALL_TOUCHED",
|
|
846
820
|
fields: allFields
|
|
@@ -850,11 +824,7 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
850
824
|
const setFieldValue = useCallback(
|
|
851
825
|
(field, value, shouldValidate = validateOnChange) => {
|
|
852
826
|
const baseValues = pendingValuesRef.current ?? formStateRef.current.values;
|
|
853
|
-
const updatedValues = setValueByPath(
|
|
854
|
-
baseValues,
|
|
855
|
-
field,
|
|
856
|
-
value
|
|
857
|
-
);
|
|
827
|
+
const updatedValues = setValueByPath(baseValues, field, value);
|
|
858
828
|
pendingValuesRef.current = updatedValues;
|
|
859
829
|
onFieldChangeRef.current?.(field, value, updatedValues);
|
|
860
830
|
pendingValuesRef.current = null;
|
|
@@ -900,24 +870,14 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
900
870
|
}
|
|
901
871
|
}
|
|
902
872
|
},
|
|
903
|
-
[
|
|
904
|
-
formState.values,
|
|
905
|
-
formState.touched,
|
|
906
|
-
validateOnBlur,
|
|
907
|
-
validateOnChange,
|
|
908
|
-
validateForm,
|
|
909
|
-
runValidationPipeline
|
|
910
|
-
]
|
|
911
|
-
);
|
|
912
|
-
const setServerErrors = useCallback(
|
|
913
|
-
(serverErrors) => {
|
|
914
|
-
dispatch({
|
|
915
|
-
type: "SET_SERVER_ERRORS",
|
|
916
|
-
errors: serverErrors
|
|
917
|
-
});
|
|
918
|
-
},
|
|
919
|
-
[]
|
|
873
|
+
[formState.values, formState.touched, validateOnBlur, validateOnChange, validateForm, runValidationPipeline]
|
|
920
874
|
);
|
|
875
|
+
const setServerErrors = useCallback((serverErrors) => {
|
|
876
|
+
dispatch({
|
|
877
|
+
type: "SET_SERVER_ERRORS",
|
|
878
|
+
errors: serverErrors
|
|
879
|
+
});
|
|
880
|
+
}, []);
|
|
921
881
|
const clearServerErrors = useCallback(() => {
|
|
922
882
|
dispatch({
|
|
923
883
|
type: "CLEAR_SERVER_ERRORS"
|
|
@@ -936,11 +896,7 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
936
896
|
const { values, clientErrors, serverErrors } = formStateRef.current;
|
|
937
897
|
const valuePaths = collectFieldPaths(values);
|
|
938
898
|
const allPaths = Array.from(
|
|
939
|
-
/* @__PURE__ */ new Set([
|
|
940
|
-
...valuePaths,
|
|
941
|
-
...Object.keys(clientErrors),
|
|
942
|
-
...Object.keys(serverErrors)
|
|
943
|
-
])
|
|
899
|
+
/* @__PURE__ */ new Set([...valuePaths, ...Object.keys(clientErrors), ...Object.keys(serverErrors)])
|
|
944
900
|
);
|
|
945
901
|
dispatch({
|
|
946
902
|
type: "MARK_ALL_TOUCHED",
|
|
@@ -984,9 +940,7 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
984
940
|
type: "SET_SUBMITTING",
|
|
985
941
|
isSubmitting: false
|
|
986
942
|
});
|
|
987
|
-
return err(
|
|
988
|
-
fieldResults.filter((r) => r.error).map((r) => ({ path: [r.field], message: r.error }))
|
|
989
|
-
);
|
|
943
|
+
return err(fieldResults.filter((r) => r.error).map((r) => ({ path: [r.field], message: r.error })));
|
|
990
944
|
}
|
|
991
945
|
}
|
|
992
946
|
if (onSubmit) {
|
|
@@ -1038,56 +992,31 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
1038
992
|
);
|
|
1039
993
|
const getFieldProps = useCallback(
|
|
1040
994
|
(field) => {
|
|
1041
|
-
return createNativeFieldProps(
|
|
1042
|
-
field,
|
|
1043
|
-
formState.values,
|
|
1044
|
-
setFieldValue,
|
|
1045
|
-
setFieldTouched
|
|
1046
|
-
);
|
|
995
|
+
return createNativeFieldProps(field, formState.values, setFieldValue, setFieldTouched);
|
|
1047
996
|
},
|
|
1048
997
|
[formState.values, setFieldValue, setFieldTouched]
|
|
1049
998
|
);
|
|
1050
999
|
const getSelectFieldProps = useCallback(
|
|
1051
1000
|
(field) => {
|
|
1052
|
-
return createNativeSelectFieldProps(
|
|
1053
|
-
field,
|
|
1054
|
-
formState.values,
|
|
1055
|
-
setFieldValue,
|
|
1056
|
-
setFieldTouched
|
|
1057
|
-
);
|
|
1001
|
+
return createNativeSelectFieldProps(field, formState.values, setFieldValue, setFieldTouched);
|
|
1058
1002
|
},
|
|
1059
1003
|
[formState.values, setFieldValue, setFieldTouched]
|
|
1060
1004
|
);
|
|
1061
1005
|
const getCheckboxProps = useCallback(
|
|
1062
1006
|
(field) => {
|
|
1063
|
-
return createNativeCheckboxProps(
|
|
1064
|
-
field,
|
|
1065
|
-
formState.values,
|
|
1066
|
-
setFieldValue,
|
|
1067
|
-
setFieldTouched
|
|
1068
|
-
);
|
|
1007
|
+
return createNativeCheckboxProps(field, formState.values, setFieldValue, setFieldTouched);
|
|
1069
1008
|
},
|
|
1070
1009
|
[formState.values, setFieldValue, setFieldTouched]
|
|
1071
1010
|
);
|
|
1072
1011
|
const getSwitchProps = useCallback(
|
|
1073
1012
|
(field) => {
|
|
1074
|
-
return createNativeSwitchProps(
|
|
1075
|
-
field,
|
|
1076
|
-
formState.values,
|
|
1077
|
-
setFieldValue,
|
|
1078
|
-
setFieldTouched
|
|
1079
|
-
);
|
|
1013
|
+
return createNativeSwitchProps(field, formState.values, setFieldValue, setFieldTouched);
|
|
1080
1014
|
},
|
|
1081
1015
|
[formState.values, setFieldValue, setFieldTouched]
|
|
1082
1016
|
);
|
|
1083
1017
|
const getSliderProps = useCallback(
|
|
1084
1018
|
(field) => {
|
|
1085
|
-
return createNativeSliderProps(
|
|
1086
|
-
field,
|
|
1087
|
-
formState.values,
|
|
1088
|
-
setFieldValue,
|
|
1089
|
-
setFieldTouched
|
|
1090
|
-
);
|
|
1019
|
+
return createNativeSliderProps(field, formState.values, setFieldValue, setFieldTouched);
|
|
1091
1020
|
},
|
|
1092
1021
|
[formState.values, setFieldValue, setFieldTouched]
|
|
1093
1022
|
);
|
|
@@ -1105,12 +1034,7 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
1105
1034
|
);
|
|
1106
1035
|
const getFileFieldProps = useCallback(
|
|
1107
1036
|
(field) => {
|
|
1108
|
-
return createNativeFileFieldProps(
|
|
1109
|
-
field,
|
|
1110
|
-
formState.values,
|
|
1111
|
-
setFieldValue,
|
|
1112
|
-
setFieldTouched
|
|
1113
|
-
);
|
|
1037
|
+
return createNativeFileFieldProps(field, formState.values, setFieldValue, setFieldTouched);
|
|
1114
1038
|
},
|
|
1115
1039
|
[formState.values, setFieldValue, setFieldTouched]
|
|
1116
1040
|
);
|
|
@@ -1128,49 +1052,13 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
1128
1052
|
);
|
|
1129
1053
|
const arrayHelpersImpl = useCallback(
|
|
1130
1054
|
(field) => {
|
|
1131
|
-
const getFieldPropsAtPath = (path) => createNativeFieldProps(
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
);
|
|
1137
|
-
const
|
|
1138
|
-
path,
|
|
1139
|
-
formState.values,
|
|
1140
|
-
setFieldValue,
|
|
1141
|
-
setFieldTouched
|
|
1142
|
-
);
|
|
1143
|
-
const getSliderPropsAtPath = (path) => createNativeSliderProps(
|
|
1144
|
-
path,
|
|
1145
|
-
formState.values,
|
|
1146
|
-
setFieldValue,
|
|
1147
|
-
setFieldTouched
|
|
1148
|
-
);
|
|
1149
|
-
const getCheckboxPropsAtPath = (path) => createNativeCheckboxProps(
|
|
1150
|
-
path,
|
|
1151
|
-
formState.values,
|
|
1152
|
-
setFieldValue,
|
|
1153
|
-
setFieldTouched
|
|
1154
|
-
);
|
|
1155
|
-
const getSwitchPropsAtPath = (path) => createNativeSwitchProps(
|
|
1156
|
-
path,
|
|
1157
|
-
formState.values,
|
|
1158
|
-
setFieldValue,
|
|
1159
|
-
setFieldTouched
|
|
1160
|
-
);
|
|
1161
|
-
const getFileFieldPropsAtPath = (path) => createNativeFileFieldProps(
|
|
1162
|
-
path,
|
|
1163
|
-
formState.values,
|
|
1164
|
-
setFieldValue,
|
|
1165
|
-
setFieldTouched
|
|
1166
|
-
);
|
|
1167
|
-
const getRadioGroupOptionPropsAtPath = (path, opt) => createRadioGroupOptionProps(
|
|
1168
|
-
path,
|
|
1169
|
-
opt,
|
|
1170
|
-
formState.values,
|
|
1171
|
-
setFieldValue,
|
|
1172
|
-
setFieldTouched
|
|
1173
|
-
);
|
|
1055
|
+
const getFieldPropsAtPath = (path) => createNativeFieldProps(path, formState.values, setFieldValue, setFieldTouched);
|
|
1056
|
+
const getSelectFieldPropsAtPath = (path) => createNativeSelectFieldProps(path, formState.values, setFieldValue, setFieldTouched);
|
|
1057
|
+
const getSliderPropsAtPath = (path) => createNativeSliderProps(path, formState.values, setFieldValue, setFieldTouched);
|
|
1058
|
+
const getCheckboxPropsAtPath = (path) => createNativeCheckboxProps(path, formState.values, setFieldValue, setFieldTouched);
|
|
1059
|
+
const getSwitchPropsAtPath = (path) => createNativeSwitchProps(path, formState.values, setFieldValue, setFieldTouched);
|
|
1060
|
+
const getFileFieldPropsAtPath = (path) => createNativeFileFieldProps(path, formState.values, setFieldValue, setFieldTouched);
|
|
1061
|
+
const getRadioGroupOptionPropsAtPath = (path, opt) => createRadioGroupOptionProps(path, opt, formState.values, setFieldValue, setFieldTouched);
|
|
1174
1062
|
const getFieldErrorAtPath = (path) => formState.touched[path] ? errors[path] : void 0;
|
|
1175
1063
|
const getFieldIdAtPath = (path, optionValue) => optionValue !== void 0 ? `${path}-${String(optionValue)}` : path;
|
|
1176
1064
|
const arrayValue = getValueByPath(formState.values, field) || [];
|
|
@@ -1189,13 +1077,7 @@ var useForm = (validatorOrSchema, options) => {
|
|
|
1189
1077
|
getFieldIdAtPath
|
|
1190
1078
|
);
|
|
1191
1079
|
},
|
|
1192
|
-
[
|
|
1193
|
-
formState.values,
|
|
1194
|
-
formState.touched,
|
|
1195
|
-
errors,
|
|
1196
|
-
setFieldValue,
|
|
1197
|
-
setFieldTouched
|
|
1198
|
-
]
|
|
1080
|
+
[formState.values, formState.touched, errors, setFieldValue, setFieldTouched]
|
|
1199
1081
|
);
|
|
1200
1082
|
const arrayHelpers = arrayHelpersImpl;
|
|
1201
1083
|
return {
|