Skip to content

Commit 6c2a50b

Browse files
committed
Fix element saving broken by unchecked-checkbox submission change
The previous commit stopped submitting empty values for unchecked checkboxes. This broke element saving in ViewMapAddModify: the toggle_<attr> checkboxes control whether an attribute overrides its inherited value, and the PHP code used has_var('toggle_' . $attr) to detect whether a toggle was rendered in the form at all (vs. the attribute being a must-field with no toggle). With unchecked toggles no longer submitted, has_var returned false for unchecked toggles too, causing all toggled-off attributes to be treated as "no toggle = include unconditionally", which selected all elements. Fix by rendering a hidden sentinel field (_has_toggle_<attr>) alongside each toggle checkbox. has_var now checks the sentinel, which is always submitted as a hidden field regardless of the checkbox state, so the distinction between "toggle present but unchecked" and "no toggle rendered" is preserved.
1 parent a381a55 commit 6c2a50b

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FIX: Saving map elements incorrectly applied all attributes after the unchecked-checkbox submission fix

share/server/core/classes/ViewMapAddModify.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private function filterMapAttrs()
7979

8080
if (
8181
(isset($attrDefs[$attr]['must']) && $attrDefs[$attr]['must'] == '1')
82-
|| !has_var('toggle_' . $attr)
82+
|| !has_var('_has_toggle_' . $attr)
8383
|| get_checkbox('toggle_' . $attr)
8484
) {
8585
if (isset($attrDefs[$attr]['array']) && $attrDefs[$attr]['array']) {
@@ -462,6 +462,12 @@ private function drawField($propname, $prop, $properties)
462462
// Add a checkbox to toggle the usage of an attribute. But only add it for
463463
// non-must attributes.
464464
if (!$prop['must'] && $fieldType != 'readonly') {
465+
// Sentinel hidden field so the server can detect that this toggle exists
466+
// in the form regardless of whether the checkbox is checked or not.
467+
// Unchecked checkboxes are not submitted by the browser (or by getFormParams),
468+
// so has_var('toggle_X') alone cannot distinguish "toggle rendered but unchecked"
469+
// from "no toggle rendered at all".
470+
hidden('_has_toggle_' . $propname, '1');
465471
checkbox(
466472
'toggle_' . $propname,
467473
$isInherited === false,

0 commit comments

Comments
 (0)