remix-validated-form 4.2.0 → 4.4.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/.turbo/turbo-build.log +15 -9
- package/README.md +1 -0
- package/browser/ValidatedForm.js +16 -26
- package/browser/hooks.d.ts +2 -0
- package/browser/hooks.js +20 -9
- package/browser/internal/MultiValueMap.d.ts +2 -0
- package/browser/internal/MultiValueMap.js +4 -0
- package/browser/internal/getInputProps.js +2 -1
- package/browser/internal/hooks.d.ts +20 -9
- package/browser/internal/hooks.js +32 -23
- package/browser/internal/logic/getRadioChecked.js +10 -0
- package/browser/internal/reset.d.ts +28 -0
- package/browser/internal/reset.js +13 -0
- package/browser/internal/state/cleanup.d.ts +2 -0
- package/browser/internal/state/cleanup.js +6 -0
- package/browser/internal/state/controlledFieldStore.d.ts +24 -0
- package/browser/internal/state/controlledFieldStore.js +57 -0
- package/browser/internal/state/controlledFields.d.ts +6 -62
- package/browser/internal/state/controlledFields.js +36 -63
- package/browser/internal/state/createFormStore.d.ts +40 -0
- package/browser/internal/state/createFormStore.js +83 -0
- package/browser/internal/state/storeFamily.d.ts +9 -0
- package/browser/internal/state/storeFamily.js +18 -0
- package/browser/internal/state/storeHooks.d.ts +5 -0
- package/browser/internal/state/storeHooks.js +10 -0
- package/browser/internal/state.d.ts +0 -27
- package/browser/internal/state.js +0 -5
- package/browser/unreleased/formStateHooks.d.ts +15 -0
- package/browser/unreleased/formStateHooks.js +23 -14
- package/browser/userFacingFormContext.d.ts +8 -0
- package/browser/userFacingFormContext.js +5 -4
- package/dist/remix-validated-form.cjs.js +17 -0
- package/dist/remix-validated-form.es.js +2844 -0
- package/dist/remix-validated-form.umd.js +17 -0
- package/{build → dist/types}/ValidatedForm.d.ts +0 -0
- package/{build → dist/types}/hooks.d.ts +2 -0
- package/{build → dist/types}/index.d.ts +0 -0
- package/{build → dist/types}/internal/MultiValueMap.d.ts +2 -0
- package/{build → dist/types}/internal/constants.d.ts +0 -0
- package/{build → dist/types}/internal/flatten.d.ts +0 -0
- package/{build → dist/types}/internal/formContext.d.ts +0 -0
- package/{build → dist/types}/internal/getInputProps.d.ts +0 -0
- package/dist/types/internal/hooks.d.ts +32 -0
- package/{build → dist/types}/internal/hydratable.d.ts +0 -0
- package/{build → dist/types}/internal/logic/getCheckboxChecked.d.ts +0 -0
- package/{build → dist/types}/internal/logic/getRadioChecked.d.ts +0 -0
- package/dist/types/internal/state/cleanup.d.ts +2 -0
- package/dist/types/internal/state/controlledFieldStore.d.ts +24 -0
- package/dist/types/internal/state/controlledFields.d.ts +6 -0
- package/dist/types/internal/state/createFormStore.d.ts +40 -0
- package/dist/types/internal/state/storeFamily.d.ts +9 -0
- package/dist/types/internal/state/storeHooks.d.ts +5 -0
- package/{build → dist/types}/internal/submissionCallbacks.d.ts +0 -0
- package/{build → dist/types}/internal/util.d.ts +0 -0
- package/{build → dist/types}/server.d.ts +0 -0
- package/{build → dist/types}/unreleased/formStateHooks.d.ts +15 -0
- package/{build → dist/types}/userFacingFormContext.d.ts +8 -0
- package/{build → dist/types}/validation/createValidator.d.ts +0 -0
- package/{build → dist/types}/validation/types.d.ts +0 -0
- package/package.json +11 -9
- package/src/ValidatedForm.tsx +25 -43
- package/src/hooks.ts +29 -17
- package/src/internal/MultiValueMap.ts +6 -0
- package/src/internal/getInputProps.test.ts +251 -0
- package/src/internal/getInputProps.ts +2 -1
- package/src/internal/hooks.ts +69 -45
- package/src/internal/logic/getRadioChecked.ts +11 -0
- package/src/internal/state/cleanup.ts +8 -0
- package/src/internal/state/controlledFieldStore.ts +91 -0
- package/src/internal/state/controlledFields.ts +78 -0
- package/src/internal/state/createFormStore.ts +152 -0
- package/src/internal/state/storeFamily.ts +24 -0
- package/src/internal/state/storeHooks.ts +22 -0
- package/src/unreleased/formStateHooks.ts +50 -27
- package/src/userFacingFormContext.ts +17 -5
- package/src/validation/validation.test.ts +304 -0
- package/tsconfig.json +4 -1
- package/vite.config.ts +7 -0
- package/.turbo/turbo-test.log +0 -11
- package/browser/components.d.ts +0 -7
- package/browser/components.js +0 -10
- package/browser/internal/SingleTypeMultiValueMap.d.ts +0 -9
- package/browser/internal/SingleTypeMultiValueMap.js +0 -41
- package/browser/internal/customState.d.ts +0 -105
- package/browser/internal/customState.js +0 -46
- package/browser/internal/hooks-valtio.d.ts +0 -18
- package/browser/internal/hooks-valtio.js +0 -110
- package/browser/internal/hooks-zustand.d.ts +0 -16
- package/browser/internal/hooks-zustand.js +0 -100
- package/browser/internal/immerMiddleware.d.ts +0 -6
- package/browser/internal/immerMiddleware.js +0 -7
- package/browser/internal/logic/elementUtils.d.ts +0 -3
- package/browser/internal/logic/elementUtils.js +0 -3
- package/browser/internal/logic/getCheckboxChecked copy.d.ts +0 -1
- package/browser/internal/logic/getCheckboxChecked copy.js +0 -9
- package/browser/internal/logic/setFieldValue.d.ts +0 -1
- package/browser/internal/logic/setFieldValue.js +0 -40
- package/browser/internal/logic/setInputValueInForm.d.ts +0 -1
- package/browser/internal/logic/setInputValueInForm.js +0 -77
- package/browser/internal/setFieldValue.d.ts +0 -20
- package/browser/internal/setFieldValue.js +0 -83
- package/browser/internal/setFormValues.d.ts +0 -2
- package/browser/internal/setFormValues.js +0 -26
- package/browser/internal/state/setFieldValue.d.ts +0 -0
- package/browser/internal/state/setFieldValue.js +0 -1
- package/browser/internal/state-valtio.d.ts +0 -62
- package/browser/internal/state-valtio.js +0 -69
- package/browser/internal/state-zustand.d.ts +0 -47
- package/browser/internal/state-zustand.js +0 -85
- package/browser/internal/test.d.ts +0 -0
- package/browser/internal/test.js +0 -15
- package/browser/internal/useMultiValueMap.d.ts +0 -1
- package/browser/internal/useMultiValueMap.js +0 -11
- package/browser/internal/watch.d.ts +0 -18
- package/browser/internal/watch.js +0 -122
- package/browser/lowLevelHooks.d.ts +0 -0
- package/browser/lowLevelHooks.js +0 -1
- package/browser/test-data/testFormData.d.ts +0 -15
- package/browser/test-data/testFormData.js +0 -46
- package/browser/types.d.ts +0 -1
- package/browser/types.js +0 -1
- package/browser/validation/validation.test.d.ts +0 -1
- package/browser/validation/validation.test.js +0 -274
- package/browser/validation/withYup.d.ts +0 -6
- package/browser/validation/withYup.js +0 -40
- package/browser/validation/withZod.d.ts +0 -6
- package/browser/validation/withZod.js +0 -50
- package/build/ValidatedForm.js +0 -257
- package/build/hooks.js +0 -79
- package/build/index.js +0 -18
- package/build/internal/MultiValueMap.js +0 -44
- package/build/internal/SingleTypeMultiValueMap.d.ts +0 -8
- package/build/internal/SingleTypeMultiValueMap.js +0 -45
- package/build/internal/constants.js +0 -7
- package/build/internal/flatten.js +0 -14
- package/build/internal/formContext.js +0 -5
- package/build/internal/getInputProps.js +0 -57
- package/build/internal/hooks-valtio.d.ts +0 -18
- package/build/internal/hooks-valtio.js +0 -128
- package/build/internal/hooks-zustand.d.ts +0 -16
- package/build/internal/hooks-zustand.js +0 -117
- package/build/internal/hooks.d.ts +0 -21
- package/build/internal/hooks.js +0 -128
- package/build/internal/hydratable.js +0 -17
- package/build/internal/immerMiddleware.d.ts +0 -6
- package/build/internal/immerMiddleware.js +0 -14
- package/build/internal/logic/elementUtils.d.ts +0 -3
- package/build/internal/logic/elementUtils.js +0 -9
- package/build/internal/logic/getCheckboxChecked.js +0 -13
- package/build/internal/logic/getRadioChecked.js +0 -9
- package/build/internal/logic/setFieldValue.d.ts +0 -1
- package/build/internal/logic/setFieldValue.js +0 -47
- package/build/internal/logic/setInputValueInForm.d.ts +0 -1
- package/build/internal/logic/setInputValueInForm.js +0 -84
- package/build/internal/setFormValues.d.ts +0 -2
- package/build/internal/setFormValues.js +0 -33
- package/build/internal/state/atomUtils.d.ts +0 -38
- package/build/internal/state/atomUtils.js +0 -13
- package/build/internal/state/controlledFields.d.ts +0 -62
- package/build/internal/state/controlledFields.js +0 -85
- package/build/internal/state-valtio.d.ts +0 -62
- package/build/internal/state-valtio.js +0 -83
- package/build/internal/state-zustand.d.ts +0 -47
- package/build/internal/state-zustand.js +0 -91
- package/build/internal/state.d.ts +0 -370
- package/build/internal/state.js +0 -76
- package/build/internal/submissionCallbacks.js +0 -17
- package/build/internal/test.d.ts +0 -1
- package/build/internal/test.js +0 -12
- package/build/internal/util.js +0 -41
- package/build/internal/watch.d.ts +0 -20
- package/build/internal/watch.js +0 -126
- package/build/server.js +0 -32
- package/build/types.d.ts +0 -1
- package/build/types.js +0 -2
- package/build/unreleased/formStateHooks.js +0 -59
- package/build/userFacingFormContext.js +0 -30
- package/build/validation/createValidator.js +0 -45
- package/build/validation/types.js +0 -2
- package/src/internal/state/atomUtils.ts +0 -13
- package/src/internal/state.ts +0 -132
package/.turbo/turbo-test.log
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
[2K[1G[2m$ jest src[22m
|
2
|
-
[1mNo tests found, exiting with code 1[22m
|
3
|
-
Run with `--passWithNoTests` to exit with code 0
|
4
|
-
In [1m/Users/aaronpettengill/dev/remix-validated-form/packages/remix-validated-form[22m
|
5
|
-
68 files checked.
|
6
|
-
testMatch: [33m**/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x)[39m - 2 matches
|
7
|
-
testPathIgnorePatterns: [33m/node_modules/[39m - 68 matches
|
8
|
-
testRegex: - 0 matches
|
9
|
-
Pattern: [33msrc[39m - 0 matches
|
10
|
-
[2K[1G[34minfo[39m Visit [1mhttps://yarnpkg.com/en/docs/cli/run[22m for documentation about this command.
|
11
|
-
[2K[1G[31merror[39m Command failed with exit code 1.
|
package/browser/components.d.ts
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import { HTMLProps } from "react";
|
2
|
-
declare type WithRequiredName<T extends {
|
3
|
-
name?: string;
|
4
|
-
}> = T & Required<Pick<T, "name">>;
|
5
|
-
export declare const ValidatedInput: ({ name, form, ...rest }: WithRequiredName<HTMLProps<HTMLInputElement>>) => JSX.Element;
|
6
|
-
export declare const ValidatedTextarea: ({ name, form, ...rest }: WithRequiredName<HTMLProps<HTMLTextAreaElement>>) => JSX.Element;
|
7
|
-
export {};
|
package/browser/components.js
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { useField } from ".";
|
3
|
-
export const ValidatedInput = ({ name, form, ...rest }) => {
|
4
|
-
const { getInputProps } = useField(name, { formId: form });
|
5
|
-
return _jsx("input", { ...getInputProps(rest) }, void 0);
|
6
|
-
};
|
7
|
-
export const ValidatedTextarea = ({ name, form, ...rest }) => {
|
8
|
-
const { getInputProps } = useField(name, { formId: form });
|
9
|
-
return _jsx("textarea", { ...getInputProps(rest) }, void 0);
|
10
|
-
};
|
@@ -1,9 +0,0 @@
|
|
1
|
-
export declare class MultiValueMap<Key, Value> {
|
2
|
-
private dict;
|
3
|
-
add: (key: Key, value: Value) => void;
|
4
|
-
remove: (key: Key, value: Value) => void;
|
5
|
-
getAll: (key: Key) => Value[];
|
6
|
-
entries: () => IterableIterator<[Key, Value[]]>;
|
7
|
-
has: (key: Key) => boolean;
|
8
|
-
}
|
9
|
-
export declare const useMultiValueMap: <Key, Value>() => () => MultiValueMap<Key, Value>;
|
@@ -1,41 +0,0 @@
|
|
1
|
-
import { useRef } from "react";
|
2
|
-
export class MultiValueMap {
|
3
|
-
constructor() {
|
4
|
-
this.dict = new Map();
|
5
|
-
this.add = (key, value) => {
|
6
|
-
var _a;
|
7
|
-
this.dict.set(key, [...((_a = this.dict.get(key)) !== null && _a !== void 0 ? _a : []), value]);
|
8
|
-
if (this.dict.has(key)) {
|
9
|
-
this.dict.get(key).push(value);
|
10
|
-
}
|
11
|
-
else {
|
12
|
-
this.dict.set(key, [value]);
|
13
|
-
}
|
14
|
-
};
|
15
|
-
this.remove = (key, value) => {
|
16
|
-
if (!this.dict.has(key))
|
17
|
-
return;
|
18
|
-
const array = this.dict.get(key);
|
19
|
-
const index = array.indexOf(value);
|
20
|
-
if (index !== -1)
|
21
|
-
array.splice(index, 1);
|
22
|
-
if (array.length === 0)
|
23
|
-
this.dict.delete(key);
|
24
|
-
};
|
25
|
-
this.getAll = (key) => {
|
26
|
-
var _a;
|
27
|
-
return (_a = this.dict.get(key)) !== null && _a !== void 0 ? _a : [];
|
28
|
-
};
|
29
|
-
this.entries = () => this.dict.entries();
|
30
|
-
this.has = (key) => this.dict.has(key);
|
31
|
-
}
|
32
|
-
}
|
33
|
-
export const useMultiValueMap = () => {
|
34
|
-
const ref = useRef(null);
|
35
|
-
return () => {
|
36
|
-
if (ref.current)
|
37
|
-
return ref.current;
|
38
|
-
ref.current = new MultiValueMap();
|
39
|
-
return ref.current;
|
40
|
-
};
|
41
|
-
};
|
@@ -1,105 +0,0 @@
|
|
1
|
-
import { Atom } from "jotai";
|
2
|
-
import { InternalFormId } from "./state/atomUtils";
|
3
|
-
export declare const unregisterAtomsFamily: {
|
4
|
-
(param: InternalFormId): Atom<Atom<any>[]> & {
|
5
|
-
write: (get: {
|
6
|
-
<Value>(atom: Atom<Value | Promise<Value>>): Value;
|
7
|
-
<Value_1>(atom: Atom<Promise<Value_1>>): Value_1;
|
8
|
-
<Value_2>(atom: Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
9
|
-
} & {
|
10
|
-
<Value_3>(atom: Atom<Value_3 | Promise<Value_3>>, options: {
|
11
|
-
unstable_promise: true;
|
12
|
-
}): Value_3 | Promise<Value_3>;
|
13
|
-
<Value_4>(atom: Atom<Promise<Value_4>>, options: {
|
14
|
-
unstable_promise: true;
|
15
|
-
}): Value_4 | Promise<Value_4>;
|
16
|
-
<Value_5>(atom: Atom<Value_5>, options: {
|
17
|
-
unstable_promise: true;
|
18
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
19
|
-
}, set: {
|
20
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
21
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
22
|
-
}, update: Atom<any>[] | ((prev: Atom<any>[]) => Atom<any>[])) => void;
|
23
|
-
onMount?: (<S extends (update: Atom<any>[] | ((prev: Atom<any>[]) => Atom<any>[])) => void>(setAtom: S) => void | (() => void)) | undefined;
|
24
|
-
} & {
|
25
|
-
init: Atom<any>[];
|
26
|
-
};
|
27
|
-
remove(param: InternalFormId): void;
|
28
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
29
|
-
};
|
30
|
-
export declare const createCustomFormState: <T>(defaultValue: T) => {
|
31
|
-
__atomFamily: {
|
32
|
-
(param: InternalFormId): Atom<T> & {
|
33
|
-
write: (get: {
|
34
|
-
<Value>(atom: Atom<Value | Promise<Value>>): Value;
|
35
|
-
<Value_1>(atom: Atom<Promise<Value_1>>): Value_1;
|
36
|
-
<Value_2>(atom: Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
37
|
-
} & {
|
38
|
-
<Value_3>(atom: Atom<Value_3 | Promise<Value_3>>, options: {
|
39
|
-
unstable_promise: true;
|
40
|
-
}): Value_3 | Promise<Value_3>;
|
41
|
-
<Value_4>(atom: Atom<Promise<Value_4>>, options: {
|
42
|
-
unstable_promise: true;
|
43
|
-
}): Value_4 | Promise<Value_4>;
|
44
|
-
<Value_5>(atom: Atom<Value_5>, options: {
|
45
|
-
unstable_promise: true;
|
46
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
47
|
-
}, set: {
|
48
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
49
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
50
|
-
}, update: T | ((prev: T) => T)) => void;
|
51
|
-
onMount?: (<S extends import("jotai/core/atom").SetAtom<T | ((prev: T) => T), void>>(setAtom: S) => void | (() => void)) | undefined;
|
52
|
-
} & {
|
53
|
-
init: T;
|
54
|
-
};
|
55
|
-
remove(param: InternalFormId): void;
|
56
|
-
setShouldRemove(shouldRemove: ((createdAt: number, param: InternalFormId) => boolean) | null): void;
|
57
|
-
};
|
58
|
-
__registerAtom: Atom<null> & {
|
59
|
-
write: (get: {
|
60
|
-
<Value>(atom: Atom<Value | Promise<Value>>): Value;
|
61
|
-
<Value_1>(atom: Atom<Promise<Value_1>>): Value_1;
|
62
|
-
<Value_2>(atom: Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
63
|
-
} & {
|
64
|
-
<Value_3>(atom: Atom<Value_3 | Promise<Value_3>>, options: {
|
65
|
-
unstable_promise: true;
|
66
|
-
}): Value_3 | Promise<Value_3>;
|
67
|
-
<Value_4>(atom: Atom<Promise<Value_4>>, options: {
|
68
|
-
unstable_promise: true;
|
69
|
-
}): Value_4 | Promise<Value_4>;
|
70
|
-
<Value_5>(atom: Atom<Value_5>, options: {
|
71
|
-
unstable_promise: true;
|
72
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
73
|
-
}, set: {
|
74
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
75
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
76
|
-
}, update: InternalFormId) => void;
|
77
|
-
onMount?: (<S_1 extends (update: InternalFormId) => void>(setAtom: S_1) => void | (() => void)) | undefined;
|
78
|
-
} & {
|
79
|
-
init: null;
|
80
|
-
};
|
81
|
-
__unregisterAtom: Atom<null> & {
|
82
|
-
write: (get: {
|
83
|
-
<Value>(atom: Atom<Value | Promise<Value>>): Value;
|
84
|
-
<Value_1>(atom: Atom<Promise<Value_1>>): Value_1;
|
85
|
-
<Value_2>(atom: Atom<Value_2>): Value_2 extends Promise<infer V> ? V : Value_2;
|
86
|
-
} & {
|
87
|
-
<Value_3>(atom: Atom<Value_3 | Promise<Value_3>>, options: {
|
88
|
-
unstable_promise: true;
|
89
|
-
}): Value_3 | Promise<Value_3>;
|
90
|
-
<Value_4>(atom: Atom<Promise<Value_4>>, options: {
|
91
|
-
unstable_promise: true;
|
92
|
-
}): Value_4 | Promise<Value_4>;
|
93
|
-
<Value_5>(atom: Atom<Value_5>, options: {
|
94
|
-
unstable_promise: true;
|
95
|
-
}): (Value_5 extends Promise<infer V> ? V : Value_5) | Promise<Value_5 extends Promise<infer V> ? V : Value_5>;
|
96
|
-
}, set: {
|
97
|
-
<Value_6, Result extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_6, undefined, Result>): Result;
|
98
|
-
<Value_7, Update, Result_1 extends void | Promise<void>>(atom: import("jotai").WritableAtom<Value_7, Update, Result_1>, update: Update): Result_1;
|
99
|
-
}, update: InternalFormId) => void;
|
100
|
-
onMount?: (<S_1 extends (update: InternalFormId) => void>(setAtom: S_1) => void | (() => void)) | undefined;
|
101
|
-
} & {
|
102
|
-
init: null;
|
103
|
-
};
|
104
|
-
};
|
105
|
-
export declare const useCustomFormState: <T>(state: ReturnType<typeof createCustomFormState>, formId: InternalFormId) => readonly [T, (value: T) => void];
|
@@ -1,46 +0,0 @@
|
|
1
|
-
import { atom } from "jotai";
|
2
|
-
import { useAtomCallback } from "jotai/utils";
|
3
|
-
import { useCallback, useEffect } from "react";
|
4
|
-
import { useFormAtom } from "./hooks";
|
5
|
-
import { formAtomFamily } from "./state/atomUtils";
|
6
|
-
export const unregisterAtomsFamily = formAtomFamily([]);
|
7
|
-
export const createCustomFormState = (defaultValue) => {
|
8
|
-
const atomFamily = formAtomFamily(defaultValue);
|
9
|
-
const refCountFamily = formAtomFamily(0);
|
10
|
-
const registerAtom = atom(null, (get, set, formId) => {
|
11
|
-
const refCountAtom = refCountFamily(formId);
|
12
|
-
set(refCountAtom, (prev) => prev + 1);
|
13
|
-
const newRefCount = get(refCountAtom);
|
14
|
-
if (newRefCount === 1) {
|
15
|
-
set(unregisterAtomsFamily(formId), (prev) => [...prev, unregisterAtom]);
|
16
|
-
}
|
17
|
-
});
|
18
|
-
const unregisterAtom = atom(null, (get, set, formId) => {
|
19
|
-
const refCountAtom = refCountFamily(formId);
|
20
|
-
set(refCountAtom, (prev) => prev - 1);
|
21
|
-
const newRefCount = get(refCountAtom);
|
22
|
-
if (newRefCount === 0) {
|
23
|
-
set(unregisterAtomsFamily(formId), (prev) => prev.filter((item) => item !== unregisterAtom));
|
24
|
-
atomFamily.remove(formId);
|
25
|
-
refCountFamily.remove(formId);
|
26
|
-
}
|
27
|
-
});
|
28
|
-
return {
|
29
|
-
__atomFamily: atomFamily,
|
30
|
-
__registerAtom: registerAtom,
|
31
|
-
__unregisterAtom: unregisterAtom,
|
32
|
-
};
|
33
|
-
};
|
34
|
-
export const useCustomFormState = (state, formId) => {
|
35
|
-
const atom = state.__atomFamily(formId);
|
36
|
-
const [value, setValue] = useFormAtom(atom);
|
37
|
-
const register = useAtomCallback(useCallback((_get, set) => set(state.__registerAtom, formId), [formId, state.__registerAtom]));
|
38
|
-
const unregister = useAtomCallback(useCallback((_get, set) => set(state.__unregisterAtom, formId), [formId, state.__unregisterAtom]));
|
39
|
-
useEffect(() => {
|
40
|
-
register();
|
41
|
-
return () => {
|
42
|
-
unregister();
|
43
|
-
};
|
44
|
-
}, [register, unregister]);
|
45
|
-
return [value, setValue];
|
46
|
-
};
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { useUpdateAtom } from "jotai/utils";
|
2
|
-
import { FieldErrors, ValidationErrorResponseData } from "..";
|
3
|
-
import { InternalFormContextValue } from "./formContext";
|
4
|
-
import { Hydratable } from "./hydratable";
|
5
|
-
export declare const useInternalFormContext: (formId?: string | symbol | undefined, hookName?: string | undefined) => InternalFormContextValue;
|
6
|
-
export declare function useErrorResponseForForm({ fetcher, subaction, formId, }: InternalFormContextValue): ValidationErrorResponseData | null;
|
7
|
-
export declare const useFieldErrorsForForm: (context: InternalFormContextValue) => Hydratable<FieldErrors | undefined>;
|
8
|
-
export declare const useDefaultValuesFromLoader: ({ formId, }: InternalFormContextValue) => any;
|
9
|
-
export declare const useDefaultValuesForForm: (context: InternalFormContextValue) => Hydratable<{
|
10
|
-
[fieldName: string]: any;
|
11
|
-
}>;
|
12
|
-
export declare const useHasActiveFormSubmit: ({ fetcher, }: InternalFormContextValue) => boolean;
|
13
|
-
export declare const useFieldTouched: (name: string, { formId }: InternalFormContextValue) => boolean;
|
14
|
-
export declare const useFieldError: (name: string, context: InternalFormContextValue) => string | undefined;
|
15
|
-
export declare const useFieldDefaultValue: (name: string, context: InternalFormContextValue) => any;
|
16
|
-
export declare const useFormUpdateAtom: typeof useUpdateAtom;
|
17
|
-
export declare const useClearError: (context: InternalFormContextValue) => (name: string) => void;
|
18
|
-
export declare const useSetTouched: (context: InternalFormContextValue) => (name: string, touched: boolean) => void;
|
@@ -1,110 +0,0 @@
|
|
1
|
-
import { useActionData, useMatches, useTransition } from "@remix-run/react";
|
2
|
-
import { useUpdateAtom } from "jotai/utils";
|
3
|
-
import lodashGet from "lodash/get";
|
4
|
-
import { useCallback, useContext } from "react";
|
5
|
-
import invariant from "tiny-invariant";
|
6
|
-
import { formDefaultValuesKey } from "./constants";
|
7
|
-
import { InternalFormContext } from "./formContext";
|
8
|
-
import { hydratable } from "./hydratable";
|
9
|
-
import { ATOM_SCOPE, clearErrorAtom, formRegistry, setTouchedAtom, } from "./state";
|
10
|
-
import { useFormData } from "./state-valtio";
|
11
|
-
export const useInternalFormContext = (formId, hookName) => {
|
12
|
-
const formContext = useContext(InternalFormContext);
|
13
|
-
if (formId)
|
14
|
-
return { formId };
|
15
|
-
if (formContext)
|
16
|
-
return formContext;
|
17
|
-
throw new Error(`Unable to determine form for ${hookName}. Please use it inside a form or pass a 'formId'.`);
|
18
|
-
};
|
19
|
-
export function useErrorResponseForForm({ fetcher, subaction, formId, }) {
|
20
|
-
var _a;
|
21
|
-
const actionData = useActionData();
|
22
|
-
if (fetcher) {
|
23
|
-
if ((_a = fetcher.data) === null || _a === void 0 ? void 0 : _a.fieldErrors)
|
24
|
-
return fetcher.data;
|
25
|
-
return null;
|
26
|
-
}
|
27
|
-
if (!(actionData === null || actionData === void 0 ? void 0 : actionData.fieldErrors))
|
28
|
-
return null;
|
29
|
-
// If there's an explicit id, we should ignore data that has the wrong id
|
30
|
-
if (typeof formId === "string" && actionData.formId)
|
31
|
-
return actionData.formId === formId ? actionData : null;
|
32
|
-
if ((!subaction && !actionData.subaction) ||
|
33
|
-
actionData.subaction === subaction)
|
34
|
-
return actionData;
|
35
|
-
return null;
|
36
|
-
}
|
37
|
-
export const useFieldErrorsForForm = (context) => {
|
38
|
-
const response = useErrorResponseForForm(context);
|
39
|
-
const form = useFormData(context.formId);
|
40
|
-
return hydratable.from(response === null || response === void 0 ? void 0 : response.fieldErrors, form.hydrated);
|
41
|
-
};
|
42
|
-
export const useDefaultValuesFromLoader = ({ formId, }) => {
|
43
|
-
const matches = useMatches();
|
44
|
-
if (typeof formId === "string") {
|
45
|
-
const dataKey = formDefaultValuesKey(formId);
|
46
|
-
// If multiple loaders declare the same default values,
|
47
|
-
// we should use the data from the deepest route.
|
48
|
-
const match = matches
|
49
|
-
.reverse()
|
50
|
-
.find((match) => match.data && dataKey in match.data);
|
51
|
-
return match === null || match === void 0 ? void 0 : match.data[dataKey];
|
52
|
-
}
|
53
|
-
return null;
|
54
|
-
};
|
55
|
-
export const useDefaultValuesForForm = (context) => {
|
56
|
-
const { formId, defaultValuesProp } = context;
|
57
|
-
const form = useFormData(formId);
|
58
|
-
const errorResponse = useErrorResponseForForm(context);
|
59
|
-
const defaultValuesFromLoader = useDefaultValuesFromLoader(context);
|
60
|
-
// Typical flow is:
|
61
|
-
// - Default values only available from props or server
|
62
|
-
// - Props have a higher priority than server
|
63
|
-
// - State gets hydrated with default values
|
64
|
-
// - After submit, we may need to use values from the error
|
65
|
-
if (form.hydrated)
|
66
|
-
return hydratable.hydratedData();
|
67
|
-
if (errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.repopulateFields) {
|
68
|
-
invariant(typeof errorResponse.repopulateFields === "object", "repopulateFields returned something other than an object");
|
69
|
-
return hydratable.serverData(errorResponse.repopulateFields);
|
70
|
-
}
|
71
|
-
if (defaultValuesProp)
|
72
|
-
return hydratable.serverData(defaultValuesProp);
|
73
|
-
return hydratable.serverData(defaultValuesFromLoader);
|
74
|
-
};
|
75
|
-
export const useHasActiveFormSubmit = ({ fetcher, }) => {
|
76
|
-
const transition = useTransition();
|
77
|
-
const hasActiveSubmission = fetcher
|
78
|
-
? fetcher.state === "submitting"
|
79
|
-
: !!transition.submission;
|
80
|
-
return hasActiveSubmission;
|
81
|
-
};
|
82
|
-
export const useFieldTouched = (name, { formId }) => {
|
83
|
-
const form = useFormData(formId);
|
84
|
-
return form.touchedFields[name];
|
85
|
-
};
|
86
|
-
export const useFieldError = (name, context) => {
|
87
|
-
const fieldErrors = useFieldErrorsForForm(context);
|
88
|
-
const form = useFormData(context.formId);
|
89
|
-
return fieldErrors
|
90
|
-
.map((fieldErrors) => fieldErrors === null || fieldErrors === void 0 ? void 0 : fieldErrors[name])
|
91
|
-
.hydrateTo(form.fieldErrors[name]);
|
92
|
-
};
|
93
|
-
export const useFieldDefaultValue = (name, context) => {
|
94
|
-
const defaultValues = useDefaultValuesForForm(context);
|
95
|
-
const state = useFormData(context.formId);
|
96
|
-
return defaultValues.map((val) => lodashGet(val, name)).hydrateTo(state);
|
97
|
-
};
|
98
|
-
export const useFormUpdateAtom = (atom) => useUpdateAtom(atom, ATOM_SCOPE);
|
99
|
-
export const useClearError = (context) => {
|
100
|
-
const clearError = useFormUpdateAtom(clearErrorAtom);
|
101
|
-
return useCallback((name) => {
|
102
|
-
clearError({ name, formAtom: formRegistry(context.formId) });
|
103
|
-
}, [clearError, context.formId]);
|
104
|
-
};
|
105
|
-
export const useSetTouched = (context) => {
|
106
|
-
const setTouched = useFormUpdateAtom(setTouchedAtom);
|
107
|
-
return useCallback((name, touched) => {
|
108
|
-
setTouched({ name, formAtom: formRegistry(context.formId), touched });
|
109
|
-
}, [setTouched, context.formId]);
|
110
|
-
};
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import { FieldErrors, ValidationErrorResponseData } from "..";
|
2
|
-
import { InternalFormContextValue } from "./formContext";
|
3
|
-
import { Hydratable } from "./hydratable";
|
4
|
-
export declare const useInternalFormContext: (formId?: string | symbol | undefined, hookName?: string | undefined) => InternalFormContextValue;
|
5
|
-
export declare function useErrorResponseForForm({ fetcher, subaction, formId, }: InternalFormContextValue): ValidationErrorResponseData | null;
|
6
|
-
export declare const useFieldErrorsForForm: (context: InternalFormContextValue) => Hydratable<FieldErrors | undefined>;
|
7
|
-
export declare const useDefaultValuesFromLoader: ({ formId, }: InternalFormContextValue) => any;
|
8
|
-
export declare const useDefaultValuesForForm: (context: InternalFormContextValue) => Hydratable<{
|
9
|
-
[fieldName: string]: any;
|
10
|
-
}>;
|
11
|
-
export declare const useHasActiveFormSubmit: ({ fetcher, }: InternalFormContextValue) => boolean;
|
12
|
-
export declare const useFieldTouched: (name: string, { formId }: InternalFormContextValue) => boolean;
|
13
|
-
export declare const useFieldError: (name: string, context: InternalFormContextValue) => string | undefined;
|
14
|
-
export declare const useFieldDefaultValue: (name: string, context: InternalFormContextValue) => any;
|
15
|
-
export declare const useClearError: (context: InternalFormContextValue) => (name: string) => void;
|
16
|
-
export declare const useSetTouched: (context: InternalFormContextValue) => (name: string, touched: boolean) => void;
|
@@ -1,100 +0,0 @@
|
|
1
|
-
import { useActionData, useMatches, useTransition } from "@remix-run/react";
|
2
|
-
import lodashGet from "lodash/get";
|
3
|
-
import { useContext } from "react";
|
4
|
-
import invariant from "tiny-invariant";
|
5
|
-
import { formDefaultValuesKey } from "./constants";
|
6
|
-
import { InternalFormContext } from "./formContext";
|
7
|
-
import { hydratable } from "./hydratable";
|
8
|
-
import { useStore } from "./state-zustand";
|
9
|
-
export const useInternalFormContext = (formId, hookName) => {
|
10
|
-
const formContext = useContext(InternalFormContext);
|
11
|
-
if (formId)
|
12
|
-
return { formId };
|
13
|
-
if (formContext)
|
14
|
-
return formContext;
|
15
|
-
throw new Error(`Unable to determine form for ${hookName}. Please use it inside a form or pass a 'formId'.`);
|
16
|
-
};
|
17
|
-
export function useErrorResponseForForm({ fetcher, subaction, formId, }) {
|
18
|
-
var _a;
|
19
|
-
const actionData = useActionData();
|
20
|
-
if (fetcher) {
|
21
|
-
if ((_a = fetcher.data) === null || _a === void 0 ? void 0 : _a.fieldErrors)
|
22
|
-
return fetcher.data;
|
23
|
-
return null;
|
24
|
-
}
|
25
|
-
if (!(actionData === null || actionData === void 0 ? void 0 : actionData.fieldErrors))
|
26
|
-
return null;
|
27
|
-
// If there's an explicit id, we should ignore data that has the wrong id
|
28
|
-
if (typeof formId === "string" && actionData.formId)
|
29
|
-
return actionData.formId === formId ? actionData : null;
|
30
|
-
if ((!subaction && !actionData.subaction) ||
|
31
|
-
actionData.subaction === subaction)
|
32
|
-
return actionData;
|
33
|
-
return null;
|
34
|
-
}
|
35
|
-
export const useFieldErrorsForForm = (context) => {
|
36
|
-
const response = useErrorResponseForForm(context);
|
37
|
-
const hydrated = useStore((state) => state.form(context.formId).hydrated);
|
38
|
-
return hydratable.from(response === null || response === void 0 ? void 0 : response.fieldErrors, hydrated);
|
39
|
-
};
|
40
|
-
export const useDefaultValuesFromLoader = ({ formId, }) => {
|
41
|
-
const matches = useMatches();
|
42
|
-
if (typeof formId === "string") {
|
43
|
-
const dataKey = formDefaultValuesKey(formId);
|
44
|
-
// If multiple loaders declare the same default values,
|
45
|
-
// we should use the data from the deepest route.
|
46
|
-
const match = matches
|
47
|
-
.reverse()
|
48
|
-
.find((match) => match.data && dataKey in match.data);
|
49
|
-
return match === null || match === void 0 ? void 0 : match.data[dataKey];
|
50
|
-
}
|
51
|
-
return null;
|
52
|
-
};
|
53
|
-
export const useDefaultValuesForForm = (context) => {
|
54
|
-
const { formId, defaultValuesProp } = context;
|
55
|
-
const hydrated = useStore((state) => state.form(formId).hydrated);
|
56
|
-
const errorResponse = useErrorResponseForForm(context);
|
57
|
-
const defaultValuesFromLoader = useDefaultValuesFromLoader(context);
|
58
|
-
// Typical flow is:
|
59
|
-
// - Default values only available from props or server
|
60
|
-
// - Props have a higher priority than server
|
61
|
-
// - State gets hydrated with default values
|
62
|
-
// - After submit, we may need to use values from the error
|
63
|
-
if (hydrated)
|
64
|
-
return hydratable.hydratedData();
|
65
|
-
if (errorResponse === null || errorResponse === void 0 ? void 0 : errorResponse.repopulateFields) {
|
66
|
-
invariant(typeof errorResponse.repopulateFields === "object", "repopulateFields returned something other than an object");
|
67
|
-
return hydratable.serverData(errorResponse.repopulateFields);
|
68
|
-
}
|
69
|
-
if (defaultValuesProp)
|
70
|
-
return hydratable.serverData(defaultValuesProp);
|
71
|
-
return hydratable.serverData(defaultValuesFromLoader);
|
72
|
-
};
|
73
|
-
export const useHasActiveFormSubmit = ({ fetcher, }) => {
|
74
|
-
const transition = useTransition();
|
75
|
-
const hasActiveSubmission = fetcher
|
76
|
-
? fetcher.state === "submitting"
|
77
|
-
: !!transition.submission;
|
78
|
-
return hasActiveSubmission;
|
79
|
-
};
|
80
|
-
export const useFieldTouched = (name, { formId }) => {
|
81
|
-
return useStore((state) => state.form(formId).touchedFields[name]);
|
82
|
-
};
|
83
|
-
export const useFieldError = (name, context) => {
|
84
|
-
const state = useStore((state) => state.form(context.formId).fieldErrors[name]);
|
85
|
-
return useFieldErrorsForForm(context)
|
86
|
-
.map((fieldErrors) => fieldErrors === null || fieldErrors === void 0 ? void 0 : fieldErrors[name])
|
87
|
-
.hydrateTo(state);
|
88
|
-
};
|
89
|
-
export const useFieldDefaultValue = (name, context) => {
|
90
|
-
const state = useStore((state) => state.form(context.formId).defaultValues[name]);
|
91
|
-
return useDefaultValuesForForm(context)
|
92
|
-
.map((val) => lodashGet(val, name))
|
93
|
-
.hydrateTo(state);
|
94
|
-
};
|
95
|
-
export const useClearError = (context) => {
|
96
|
-
return useStore((state) => state.helpers(context.formId).clearError);
|
97
|
-
};
|
98
|
-
export const useSetTouched = (context) => {
|
99
|
-
return useStore((state) => state.helpers(context.formId).setTouched);
|
100
|
-
};
|
@@ -1,6 +0,0 @@
|
|
1
|
-
import { Draft } from "immer";
|
2
|
-
import { State, StateCreator } from "zustand";
|
3
|
-
declare type TImmerConfigFn<T extends State> = (partial: ((draft: Draft<T>) => void) | T, replace?: boolean) => void;
|
4
|
-
declare type TImmerConfig<T extends State> = StateCreator<T, TImmerConfigFn<T>>;
|
5
|
-
export declare const immer: <T extends object>(config: TImmerConfig<T>) => StateCreator<T, import("zustand").SetState<T>, import("zustand").GetState<T>, import("zustand").StoreApi<T>>;
|
6
|
-
export {};
|
@@ -1,3 +0,0 @@
|
|
1
|
-
export const isMultiselect = (node) => node instanceof HTMLSelectElement && node.multiple;
|
2
|
-
export const isCheckbox = (node) => node instanceof HTMLInputElement && node.type === "checkbox";
|
3
|
-
export const isRadio = (node) => node instanceof HTMLInputElement && node.type === "radio";
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare const getCheckboxChecked: (checkboxValue: string | undefined, newValue: unknown) => boolean | undefined;
|
@@ -1,9 +0,0 @@
|
|
1
|
-
export const getCheckboxChecked = (checkboxValue = "on", newValue) => {
|
2
|
-
if (Array.isArray(newValue))
|
3
|
-
return newValue.includes(checkboxValue);
|
4
|
-
if (typeof newValue === "boolean")
|
5
|
-
return newValue;
|
6
|
-
if (typeof newValue === "string")
|
7
|
-
return newValue === checkboxValue;
|
8
|
-
return undefined;
|
9
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare const setFieldValue: (formElement: HTMLFormElement, name: string, value: unknown) => void;
|
@@ -1,40 +0,0 @@
|
|
1
|
-
import invariant from "tiny-invariant";
|
2
|
-
import { getCheckboxChecked } from "./getCheckboxChecked";
|
3
|
-
import { getRadioChecked } from "./getRadioChecked";
|
4
|
-
const setElementValue = (element, value, name) => {
|
5
|
-
if (element instanceof HTMLSelectElement && element.multiple) {
|
6
|
-
invariant(Array.isArray(value), "Must specify an array to set the value for a multi-select");
|
7
|
-
for (const option of element.options) {
|
8
|
-
option.selected = value.includes(option.value);
|
9
|
-
}
|
10
|
-
return;
|
11
|
-
}
|
12
|
-
if (element instanceof HTMLInputElement && element.type === "checkbox") {
|
13
|
-
const newChecked = getCheckboxChecked(element.value, value);
|
14
|
-
invariant(newChecked !== undefined, `Unable to determine if checkbox should be checked. Provided value was ${value} for checkbox ${name}.`);
|
15
|
-
element.checked = newChecked;
|
16
|
-
return;
|
17
|
-
}
|
18
|
-
if (element instanceof HTMLInputElement && element.type === "radio") {
|
19
|
-
const newChecked = getRadioChecked(element.value, value);
|
20
|
-
invariant(newChecked !== undefined, `Unable to determine if radio should be checked. Provided value was ${value} for radio ${name}.`);
|
21
|
-
element.checked = newChecked;
|
22
|
-
return;
|
23
|
-
}
|
24
|
-
invariant(typeof value === "string", `Invalid value for field "${name}" which is an ${element.constructor.name}. Expected string but received ${typeof value}`);
|
25
|
-
const input = element;
|
26
|
-
input.value = value;
|
27
|
-
};
|
28
|
-
export const setFieldValue = (formElement, name, value) => {
|
29
|
-
const controlElement = formElement.elements.namedItem(name);
|
30
|
-
if (!controlElement)
|
31
|
-
return;
|
32
|
-
if (controlElement instanceof RadioNodeList) {
|
33
|
-
for (const element of controlElement) {
|
34
|
-
setElementValue(element, value, name);
|
35
|
-
}
|
36
|
-
}
|
37
|
-
else {
|
38
|
-
setElementValue(controlElement, value, name);
|
39
|
-
}
|
40
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare const setInputValueInForm: (formElement: HTMLFormElement, name: string, value: unknown[]) => void;
|
@@ -1,77 +0,0 @@
|
|
1
|
-
import invariant from "tiny-invariant";
|
2
|
-
import { isCheckbox, isMultiselect, isRadio } from "./elementUtils";
|
3
|
-
import { getCheckboxChecked } from "./getCheckboxChecked";
|
4
|
-
/**
|
5
|
-
* Helper class to track the values being set on uncontrolled fields.
|
6
|
-
* HTML is super permissive with inputs that all share the same `name`.
|
7
|
-
*/
|
8
|
-
class Values {
|
9
|
-
constructor(values) {
|
10
|
-
this.hasSetRadioValue = false;
|
11
|
-
this.remove = (value) => {
|
12
|
-
const index = this.values.indexOf(value);
|
13
|
-
const deleted = this.values.splice(index, 1);
|
14
|
-
return deleted.length > 0;
|
15
|
-
};
|
16
|
-
this.bool = (value) => {
|
17
|
-
if (getCheckboxChecked(value, this.values)) {
|
18
|
-
this.remove(value) || this.remove(true);
|
19
|
-
return true;
|
20
|
-
}
|
21
|
-
return false;
|
22
|
-
};
|
23
|
-
this.radio = (value) => {
|
24
|
-
if (this.hasSetRadioValue)
|
25
|
-
return false;
|
26
|
-
const result = this.bool(value);
|
27
|
-
if (result)
|
28
|
-
this.hasSetRadioValue = true;
|
29
|
-
return result;
|
30
|
-
};
|
31
|
-
this.str = () => { var _a; return String((_a = this.values.pop()) !== null && _a !== void 0 ? _a : ""); };
|
32
|
-
this.allValues = () => this.values;
|
33
|
-
this.warnIfLeftovers = (field) => {
|
34
|
-
if (this.values.length > 0) {
|
35
|
-
console.warn(`Could not determine how to use the value for the field ${field}. ` +
|
36
|
-
`Leftover values were: ${this.values.join(", ")}.`);
|
37
|
-
}
|
38
|
-
};
|
39
|
-
const unknownValues = Array.isArray(values) ? values : [values];
|
40
|
-
this.values = unknownValues;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
const setElementValue = (element, values, field) => {
|
44
|
-
if (isMultiselect(element)) {
|
45
|
-
for (const option of element.options) {
|
46
|
-
option.selected = values.bool(option.value);
|
47
|
-
}
|
48
|
-
return;
|
49
|
-
}
|
50
|
-
if (isCheckbox(element)) {
|
51
|
-
element.checked = values.bool(element.value);
|
52
|
-
return;
|
53
|
-
}
|
54
|
-
if (isRadio(element)) {
|
55
|
-
element.checked = values.radio(element.value);
|
56
|
-
return;
|
57
|
-
}
|
58
|
-
const input = element;
|
59
|
-
invariant(input.type !== "hidden", `Cannot set value on hidden input if it is not a controlled field. Field being updated was ${field}.`);
|
60
|
-
input.value = values.str();
|
61
|
-
};
|
62
|
-
export const setInputValueInForm = (formElement, name, value) => {
|
63
|
-
const controlElement = formElement.elements.namedItem(name);
|
64
|
-
if (!controlElement)
|
65
|
-
return;
|
66
|
-
const values = new Values(value);
|
67
|
-
if (controlElement instanceof RadioNodeList) {
|
68
|
-
for (const element of controlElement) {
|
69
|
-
setElementValue(element, values, name);
|
70
|
-
}
|
71
|
-
values.warnIfLeftovers(name);
|
72
|
-
}
|
73
|
-
else {
|
74
|
-
setElementValue(controlElement, values, name);
|
75
|
-
values.warnIfLeftovers(name);
|
76
|
-
}
|
77
|
-
};
|