You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`useFormDataIfPresent`| Legacy behavior - Do not merge defaults if there is a value for a field in `formData` even if that value is explicitly set to `undefined`|
271
271
|`useDefaultIfFormDataUndefined`| If the value of a field within the `formData` is `undefined`, then use the default value instead |
272
+
|`useDefault`| Always use the default value instead of form data |
Copy file name to clipboardExpand all lines: packages/docs/docs/api-reference/utility-functions.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -661,7 +661,7 @@ Merges the `defaults` object of type `T` into the `formData` of type `T`
661
661
When merging defaults and form data, we want to merge in this specific way:
662
662
663
663
- objects are deeply merged
664
-
- arrays are merged in such a way that:
664
+
- arrays are either replaced (when `defaultSupercedes` is true) or merged in such a way that:
665
665
- when the array is set in form data, only array entries set in form data are deeply merged; additional entries from the defaults are ignored unless `mergeExtraArrayDefaults` is true, in which case the extras are appended onto the end of the form data
666
666
- when the array is not set in form data, the default is copied over
667
667
- scalars are overwritten/set by form data
@@ -672,6 +672,7 @@ When merging defaults and form data, we want to merge in this specific way:
672
672
-[formData]: T | undefined - The form data into which the defaults will be merged
673
673
-[mergeExtraArrayDefaults=false]: boolean - If true, any additional default array entries are appended onto the formData
674
674
-[defaultSupercedesUndefined=false]: boolean - If true, an explicit undefined value will be overwritten by the default value
675
+
-[defaultSupercedes=false]: boolean - If true, a value will be overwritten by the default value
Copy file name to clipboardExpand all lines: packages/utils/src/mergeDefaultsWithFormData.ts
+24-14Lines changed: 24 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ import isNil from 'lodash/isNil';
20
20
* @param [formData] - The form data into which the defaults will be merged
21
21
* @param [mergeExtraArrayDefaults=false] - If true, any additional default array entries are appended onto the formData
22
22
* @param [defaultSupercedesUndefined=false] - If true, an explicit undefined value will be overwritten by the default value
23
-
* @param [overrideFormDataWithDefaults=false] - If true, the default value will overwrite the form data value. If the value
23
+
* @param [overrideFormDataWithDefaultsStrategy='noop'] - If not 'noop', the default value will overwrite the form data value. Values can be either replaced or merged, if the value
24
24
* doesn't exist in the default, we take it from formData and in the case where the value is set to undefined in formData.
25
25
* This is useful when we have already merged formData with defaults and want to add an additional field from formData
26
26
* that does not exist in defaults.
@@ -31,14 +31,14 @@ export default function mergeDefaultsWithFormData<T = any>(
0 commit comments