@paragrav/rhf-utils 0.0.111 → 0.0.112
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 +34 -10
- package/dist/esm/src/form/context/group/useFormGroupChildIsMountedTracker.mjs +3 -4
- package/dist/esm/src/form/context/group/useFormGroupChildIsSubmittingTracker.mjs +5 -4
- package/dist/esm/src/form/context/group/useFormGroupIsParentBusy.mjs +2 -2
- package/dist/esm/src/form/context/group/useFormGroupParentTracker.mjs +6 -5
- package/dist/types/form/context/group/useFormGroupChildIsMountedTracker.d.ts +1 -1
- package/dist/types/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +1 -1
- package/dist/types/form/context/group/useFormGroupParentTracker.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ Currently, only `zod` is supported.
|
|
|
117
117
|
}) => {
|
|
118
118
|
onError(error);
|
|
119
119
|
}}
|
|
120
|
-
//
|
|
120
|
+
// fields
|
|
121
121
|
Children={({
|
|
122
122
|
// UseRhfUtilsFormChildrenProps
|
|
123
123
|
formId, // unique id string
|
|
@@ -130,13 +130,10 @@ Currently, only `zod` is supported.
|
|
|
130
130
|
<Controller
|
|
131
131
|
name="email" // strongly-typed field name
|
|
132
132
|
render={({ field, formState: { isSubmitting } }) => (
|
|
133
|
-
<
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
disabled={isSubmitting}
|
|
138
|
-
{...field}
|
|
139
|
-
/>
|
|
133
|
+
<label>
|
|
134
|
+
Email
|
|
135
|
+
<input {...field} disabled={isSubmitting} />
|
|
136
|
+
</label>
|
|
140
137
|
)}
|
|
141
138
|
/>
|
|
142
139
|
|
|
@@ -151,7 +148,9 @@ Currently, only `zod` is supported.
|
|
|
151
148
|
If you prefer to define your `Children` component as standalone:
|
|
152
149
|
|
|
153
150
|
```tsx
|
|
154
|
-
const Children: RhfUtilsUseFormChildrenZodFC<typeof schema> = () => {};
|
|
151
|
+
const Children: RhfUtilsUseFormChildrenZodFC<typeof schema> = ({ ... }) => { };
|
|
152
|
+
|
|
153
|
+
function Children({...}: RhfUtilsUseFormChildrenZodProps<typeof schema>) { }
|
|
155
154
|
```
|
|
156
155
|
|
|
157
156
|
## `RhfUtilsFormOptions`
|
|
@@ -221,7 +220,7 @@ To get accurate orphan analysis, you must either use `FormNonFieldErrorMarker` i
|
|
|
221
220
|
Alternatively, you can use `FormErrorMessageByPath` to display error message to user:
|
|
222
221
|
|
|
223
222
|
```tsx
|
|
224
|
-
<FormErrorMessageByPath path="
|
|
223
|
+
<FormErrorMessageByPath path="street.address" />
|
|
225
224
|
```
|
|
226
225
|
|
|
227
226
|
Example use case: Field array with minimum items. (When there are no items, the error is not associated with a field and is displayed separately.)
|
|
@@ -232,3 +231,28 @@ Orphans are optionally exposed in a few places.
|
|
|
232
231
|
- And `useFlatFieldErrorsContext()` hook, which returns an object with divided into `all`, `root`, and `orphans` errors.
|
|
233
232
|
|
|
234
233
|
`FlatFieldErrors` is a flattened, simplified version of RHF's `FieldErrors`. Keys represent field paths flattened to dot notation.
|
|
234
|
+
|
|
235
|
+
## Form Groups
|
|
236
|
+
|
|
237
|
+
Sometimes you need to group multiple forms together.
|
|
238
|
+
|
|
239
|
+
Use case: disable parent form when any child is "busy"; disable all children when parent is "busy".
|
|
240
|
+
|
|
241
|
+
Use `FormGroupContextProvider` to wrap your children and parent forms.
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
<FormGroupContextProvider>
|
|
245
|
+
<ChildForm1 />
|
|
246
|
+
<ChildForm2 />
|
|
247
|
+
<ParentForm />
|
|
248
|
+
</FormGroupContextProvider>
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
In your parent form, use the hook `useFormGroupParentTracker`, which returns `boolean` value indicating whether any child forms is busy.
|
|
252
|
+
|
|
253
|
+
In children forms, there are two options. You can choose to consider form "busy" when:
|
|
254
|
+
|
|
255
|
+
- `isSubmitting` is `true` by using `useFormGroupChildIsSubmittingTracker` hook
|
|
256
|
+
- it is mounted by using `useFormGroupChildIsMountedTracker` hook
|
|
257
|
+
|
|
258
|
+
Both hooks return `boolean` value indicating whether parent form is busy.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useFormState as o } from "react-hook-form";
|
|
2
2
|
import t from "./useFormGroupChildTracker.mjs";
|
|
3
|
-
|
|
3
|
+
import u from "./useFormGroupIsParentBusy.mjs";
|
|
4
|
+
const m = () => {
|
|
4
5
|
const { isSubmitting: r } = o();
|
|
5
|
-
t(r);
|
|
6
|
-
},
|
|
6
|
+
return t(r), u();
|
|
7
|
+
}, n = m;
|
|
7
8
|
export {
|
|
8
|
-
|
|
9
|
+
n as default
|
|
9
10
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import s from "react";
|
|
2
2
|
import t from "../../useFormIsBusy.mjs";
|
|
3
3
|
import { _useFormGroupContext as e } from "./index.mjs";
|
|
4
|
-
|
|
4
|
+
import u from "./useFormGroupIsChildBusy.mjs";
|
|
5
|
+
const m = () => {
|
|
5
6
|
const r = t(), { setIsBusy: o } = e().parent;
|
|
6
|
-
s.useEffect(() => {
|
|
7
|
+
return s.useEffect(() => {
|
|
7
8
|
o(r);
|
|
8
|
-
}, [o, r]);
|
|
9
|
-
},
|
|
9
|
+
}, [o, r]), u();
|
|
10
|
+
}, f = m;
|
|
10
11
|
export {
|
|
11
|
-
|
|
12
|
+
f as default
|
|
12
13
|
};
|