Skip to content

fix: Sync perk checkbox to perk state when all perks become invalid...

stephen requested to merge sync-perk-checkbox-to-perk-state into main

fix: Sync perk checkbox to perk state when all perks become invalid selections, not just when a perk is selected

A great deal of code has been written around perk selection to ensure that it's not possible to wind up with a form state that spells out an impossible order. This is chiefly challenged by the checkbox which allows a user to deselect all perks - because beyond being a form control, it also needs to represent the state of the form accurately when other form states would invalidate its own state.

An example of this which has long been part of the site: A user navigates to the donate page. The default state is "no perks selected, with the "no perks, thanks" checkbox selected. A user selects a perk; this automatically unchecks the "no perks, thanks" checkbox, as otherwise CiviCRM would be sent donation information which states "This user did not want any perks, and also selected perk X."

Despite the testing around this feature, it appears to be possible to force the form into another type of impossible state (though one with less confusing consequences): When a donation amount sufficient to select a perk has been entered, and a perk has been selected, a user could change their donation amount to one insufficient for that perk. This would correctly deselect that perk, and make it unavailable, but the "no perks, thanks" checkbox would remain unchecked.

While this is liable to cause fewer downstream problems regarding user intent - one can reason that "no perk has been selected" overrides the tiny checkbox state which suggests "I'm cool with perks" - it may certainly cause them anyway, and it is a technically-invalid state regardless. Ergo, this MR seeks to address this oversight by properly adding this functionality to propagateDonation().

Discovered independently, so no related issue to close.

Merge request reports

Loading