-
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
Components keeping original defaultValue when editing #5123
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5123 +/- ##
=======================================
Coverage 96.75% 96.75%
=======================================
Files 778 778
Lines 26741 26741
Branches 3474 3474
=======================================
Hits 25873 25873
Misses 606 606
Partials 262 262 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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. |
f635fe0
to
4a2d424
Compare
Your comment was correct, the change of merging the So the bug was as follows: you create a form with a radio component. This component has a default value of empty string, so when you save the form the By telling formio to use our schema's (which is the formio schema + some custom stuff) we can ensure that a valid |
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 have... strong feelings... about Formio
The test covers the entire bug reproduce flow. Starting by creating a form with a radio component and saving it. This should (also with the bug still present) set the defaultValue to empty string in the database. When editing the form and opening the radio component in the json view, the defaultValue will show as `null`. Because playwright cannot target the json view correctly (certain dom elements aren't targetable), we just save the component (setting the defaultValue to `null`) and save the form. With the bug present, the database should now have the defaultValue as `null`. This bug is a combination of problems that result in the defaultValue being wrongly set by formio. The problem comes from our radio component, which defines a defaultValue in the schema. This schema is not set on the formio component, unless we specify it with `get defaultSchema`. When calculating the defaultValue, formio starts with the defaultValue on the schema, which isn't defined in the regular formio radio component schema. If the defaultValue defined on the component (via the admin) is truety, this will be used as 'real' the defaultValue. Because the defaultValue of the component was an empty string, which is falsey, and the defaultValue wasn't set by the component schema, the defaultValue was set to null. If you would edit the component and save it, then the defaultValue `null` would be saved in the database.
…properly The previous solution for a similar bug for the textfield component was a bandage fix (#4659). The real problem is that formio doesn't normally define defaultValue's. This is something that we have to define and enforce ourselfs. By setting our custom schema (which is the formio schema + some custom schema definition) we can ensure that a proper defaultValue is defined. This also makes the components more predictable. If for some reason you set the defaultValue to `null`, then this will be respected. With the previous solution, a empty string was forced as the minimum defaultValue (if the defaultValue was falsey, it would be replaced by an empty string)
This can be used by admins to automatically fix the radio components with faulty defaultValue's
02f2cf4
to
57a51ea
Compare
For the backport: To ease the pain of having to fix all radio components defaultValues by hand, i've added a fix script |
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.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