Skip to content

Commit

Permalink
🐛 [#5104] Solving default value being set to 'null'
Browse files Browse the repository at this point in the history
The `FormioUtils.fastCloneDeep(component)` makes a new instance of the component (with a new unique id). For the most part this is okay, but when the `defaultValue` is set to a falsey value (like an empty string), the `defaultValue` from `FormioUtils.fastCloneDeep(component)` will be `null`.

For the bug #4659 this was solved by manually correcting the default value of textfield and email components from `null` to `''`. This corrected the problem for these components (and ensured that these components always have a valid default value), but didn't solve the problem for other components.

By merging `original` and `FormioUtils.fastCloneDeep(component)` into one object, we retain the original component configuration and give the `componentCopy` a unique id.
The id must be unique for proper cancelation functionality (if the id of `componentCopy` is the same as the original, an error will be thrown when you edit the component > cancel editing > edit it again)
  • Loading branch information
robinmolen committed Feb 26, 2025
1 parent e7e8155 commit d64fd73
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class WebformBuilder extends WebformBuilderFormio {
// using only produce seems to affect component itself, which crashes the preview
// rebuild of formio...
// const componentCopy = produce(component, draft => draft);
const componentCopy = FormioUtils.fastCloneDeep(component);
const componentCopy = {...(original || {}), ...FormioUtils.fastCloneDeep(component)};
const ComponentClass = Components.components[componentCopy.type];

// takes care of setting the defaults from the schema etc., since `component` itself
Expand Down

0 comments on commit d64fd73

Please sign in to comment.