dev/core#2985 Original value is displayed after setting custom event field blank #25229
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This resolves https://lab.civicrm.org/dev/core/-/issues/2985:
Attempting to change the value of a custom event field from non-blank to blank results in the original value being populated in the form after the form is saved. If the form is subsequently saved again, then the original non-blank value is written to the DB.
Before
Reproduction steps
Current behaviour
The custom field displays the non-blank value. If the form is saved, the blank value currently in the DB is overwritten with the non-blank value.
After
The custom field displays the submitted value (the blank value).
Technical Details
I traced this issue down to the
customData
cache inCRM_Core_BAO_CustomGroup::formatGroupTree
. Digging revealed this to be introduced to resolve the issue described in https://issues.civicrm.org/jira/browse/CRM-16676 and https://issues.civicrm.org/jira/browse/CRM-18427:I initially removed the cache code
$submittedValues = Civi::cache('customData')->get($qfKey);
and verified that it resolved dev/core#2985, but that the issue describedCRM-16676
regressed. This eventual solution retains the cache, which is needed in the case of validation errors, but more strictly checks for null values (rather than false'y values), treating an empty string as a valid submitted value.Comments
The original Jira tickets are a bit light on detail, so whilst it's quite easy to test the issue described on dev/core#2985, it's harder to fully test all the permatations that could be impacted by this change.
It's worth noting that reproducing the issues on Jira seems quite tricky as required fields are now client-side validated. I was only able to reproduce if I manually removed the
required
class in devtools on a custom field.