@paragrav/rhf-utils 0.0.124 → 0.0.125
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 +8 -2
- package/dist/esm/devtool/LazyDevTool.mjs +1 -2
- package/dist/esm/errors/flat/context/useFlatFieldErrorsContextOutput.mjs +1 -2
- package/dist/esm/errors/flat/getFlatFieldErrors.mjs +1 -2
- package/dist/esm/form/context/utils/RhfUtilsContextProvider.mjs +17 -17
- package/dist/esm/form/utils/useFormRequestSubmit.mjs +1 -2
- package/dist/esm/submit/useResetFormOnSubmitted.mjs +2 -4
- package/dist/esm/submit/useSubmitFormOnChange.mjs +2 -4
- package/dist/esm/utils/createContext.mjs +1 -2
- package/dist/types/submit/useResetFormOnSubmitted.d.ts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -171,7 +171,10 @@ Currently, only `zod` is supported.
|
|
|
171
171
|
}}
|
|
172
172
|
utils={{
|
|
173
173
|
submitOnChange: true,
|
|
174
|
-
|
|
174
|
+
resetValuesOnSubmitted: {
|
|
175
|
+
onSuccess: 'current',
|
|
176
|
+
onError: 'defaults',
|
|
177
|
+
},
|
|
175
178
|
// custom option props
|
|
176
179
|
// (see "Extend RhfUtilsFormOptions" section)
|
|
177
180
|
enableMyFormNavigationPrompt: true,
|
|
@@ -242,7 +245,10 @@ type RhfUtilsFormOptions = {
|
|
|
242
245
|
submitOnChange?: boolean;
|
|
243
246
|
|
|
244
247
|
/** Reset form after submitted. */
|
|
245
|
-
resetFormOnSubmitted?:
|
|
248
|
+
resetFormOnSubmitted?: {
|
|
249
|
+
onSuccess?: 'defaults' | 'current';
|
|
250
|
+
onError?: 'defaults';
|
|
251
|
+
};
|
|
246
252
|
|
|
247
253
|
/** Control dev tool options. (Lazy-loaded when truthy value supplied.) */
|
|
248
254
|
devTool?: true | Pick<DevtoolUIProps, 'placement' | 'styles'>;
|
|
@@ -6,8 +6,7 @@ const a = e.lazy(
|
|
|
6
6
|
default: o.DevTool
|
|
7
7
|
}))
|
|
8
8
|
), u = ({ isDevelopment: o, props: r }) => {
|
|
9
|
-
if (!o)
|
|
10
|
-
return null;
|
|
9
|
+
if (!o) return null;
|
|
11
10
|
const { control: l } = n();
|
|
12
11
|
return /* @__PURE__ */ t(e.Suspense, { fallback: null, children: /* @__PURE__ */ t(a, { control: l, ...r }) });
|
|
13
12
|
};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { _RhfUtilsContextProvider as
|
|
8
|
-
const
|
|
1
|
+
import { jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import d from "../../../client/config/useRhfUtilsClientConfigContext.mjs";
|
|
3
|
+
import i from "../../../errors/flat/context/useFlatFieldErrorsContextOutput.mjs";
|
|
4
|
+
import u from "../../../submit/useFormOnSubmitSuccessfulAndReset.mjs";
|
|
5
|
+
import x from "../../../submit/useResetFormOnSubmitted.mjs";
|
|
6
|
+
import F from "../../../submit/useSubmitFormOnChange.mjs";
|
|
7
|
+
import { _RhfUtilsContextProvider as O } from "./useRhfUtilsContext.mjs";
|
|
8
|
+
const P = ({
|
|
9
9
|
formId: C,
|
|
10
|
-
formRef:
|
|
10
|
+
formRef: m,
|
|
11
11
|
onSubmitSuccessfulAndReset: t,
|
|
12
12
|
options: r,
|
|
13
|
-
children:
|
|
13
|
+
children: f
|
|
14
14
|
}) => {
|
|
15
15
|
var a;
|
|
16
|
-
const
|
|
17
|
-
return
|
|
16
|
+
const e = d();
|
|
17
|
+
return i((a = e == null ? void 0 : e.fieldErrors) == null ? void 0 : a.output), F(m, {
|
|
18
18
|
disabled: !(r != null && r.submitOnChange)
|
|
19
|
-
}),
|
|
19
|
+
}), x(
|
|
20
20
|
(r == null ? void 0 : r.resetFormOnSubmitted) ?? (t && {
|
|
21
|
-
onSuccess:
|
|
21
|
+
onSuccess: "defaults"
|
|
22
22
|
})
|
|
23
|
-
),
|
|
23
|
+
), u(() => {
|
|
24
24
|
t == null || t();
|
|
25
|
-
}), /* @__PURE__ */
|
|
25
|
+
}), /* @__PURE__ */ l(O, { value: { formId: C, formRef: m, options: r }, children: f });
|
|
26
26
|
};
|
|
27
27
|
export {
|
|
28
|
-
|
|
28
|
+
P as default
|
|
29
29
|
};
|
|
@@ -3,11 +3,9 @@ import n from "./useFormOnSubmitted.mjs";
|
|
|
3
3
|
const S = (e) => {
|
|
4
4
|
const { reset: r, getValues: u } = m();
|
|
5
5
|
n((s) => {
|
|
6
|
-
if (!e)
|
|
7
|
-
return;
|
|
6
|
+
if (!e) return;
|
|
8
7
|
const t = e[s ? "onSuccess" : "onError"];
|
|
9
|
-
if (!t)
|
|
10
|
-
return;
|
|
8
|
+
if (!t) return;
|
|
11
9
|
const o = t === "current" ? u() : void 0;
|
|
12
10
|
r(o, {
|
|
13
11
|
// keep submit stuff for tracking relevant state (e.g., `useFormOnSubmitSuccessful`)
|
|
@@ -3,11 +3,9 @@ import m from "../form/utils/useFormRequestSubmit.mjs";
|
|
|
3
3
|
const d = (t, e) => {
|
|
4
4
|
const u = !(e != null && e.disabled), a = m(t);
|
|
5
5
|
c.useEffect(() => {
|
|
6
|
-
if (!u)
|
|
7
|
-
return;
|
|
6
|
+
if (!u) return;
|
|
8
7
|
const r = t.current;
|
|
9
|
-
if (!r)
|
|
10
|
-
throw new Error();
|
|
8
|
+
if (!r) throw new Error();
|
|
11
9
|
const n = () => {
|
|
12
10
|
a();
|
|
13
11
|
};
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
export type UseResetFormOnSubmittedOptions = undefined | {
|
|
6
6
|
/**
|
|
7
7
|
* Reset values on submit successful.
|
|
8
|
-
* - `
|
|
8
|
+
* - `'defaults'`: reset to default values
|
|
9
9
|
* - `'current'`: reset to current values
|
|
10
10
|
*/
|
|
11
|
-
onSuccess?:
|
|
11
|
+
onSuccess?: 'defaults' | 'current';
|
|
12
12
|
/**
|
|
13
13
|
* Reset values on submit error. (reset to default values)
|
|
14
14
|
*/
|
|
15
|
-
onError?:
|
|
15
|
+
onError?: 'defaults';
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
18
|
* Handle resetting after successful submit with no server validation errors.
|