-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Components keeping original defaultValue when editing #5123
base: master
Are you sure you want to change the base?
Conversation
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)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5123 +/- ##
=======================================
Coverage 96.73% 96.73%
=======================================
Files 775 775
Lines 26662 26664 +2
Branches 3468 3469 +1
=======================================
+ Hits 25792 25794 +2
Misses 608 608
Partials 262 262 ☔ View full report in Codecov by Sentry. |
The previous solution, derived from #4659, is no-longer needed. - With the previous changes to the `WebformBuilder` (d64fd73) the correct defaultValue is used when editing a component. - To ensure that the textfield components start with an empty string as `defaultValue`, we can just define it in the schema and point the `get defaultSchema()` to our own schema. This also makes the textfield components more predictable. If for some reason you set the defaultValue to `null`, then this will be respected.
339c6c9
to
f635fe0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm terrified of this change because of the earlier issues that happened with it, and on how Formio itself figures out the default value for a component: https://github.com/formio/formio.js/blob/bebc2ad73cad138a6de0a8247df47f0085a314cc/src/components/_classes/component/Component.js#L2302
Can you please make sure that all the old reported bugs are not re-introduced and test them manually? You should be able to figure out which ones that are from the commit history/git blame.
We should also document the manual JSON editing requirement when backporting the fix. For the master branch, we can do a data migration. |
Closes #5104
Changes
When creating radio component the configuration defined in the component schema will be used. Providing an empty string as the
defaultValue
. If you leave thedefaultValue
as an empty string, save this component and edit it again, thedefaultValue
will change tonull
. ThisdefaultValue
change happens because of how we construct the component data for the edit modal.In the
WebformBuilder.editComponent
we receive thecomponent
property, which is a simplified representation of the component (a sub-set of all the component information). If thedefaultValue
is a falsey value, like in this case an empty string, thendefaultValue
won't be present in thiscomponent
prop. When reconstructing the component to its full representation, thedefaultValue
defined in the Formio component schema will be used (null
).To make sure we retain the actual component
defaultValue
, we combine theoriginal
prop (which is the original component data) and the reconstructed component data.For now i've opted to only added the
defaultValue
of the original data. Using the entireoriginal
object should be save, but to know for sure would require some more testing.Checklist
Check off the items that are completed or not relevant.
Impact on features
Release management
I have updated the translations assets (you do NOT need to provide translations)
./bin/makemessages_js.sh
./bin/compilemessages_js.sh
Dockerfile/scripts
./bin
folderCommit hygiene