Commit f3e612a5 authored by Robert Lyon's avatar Robert Lyon
Browse files

Colour form option not saving properly (Bug #1305275)



The 'customise' optional checkbox was breaking the saving of colours
for boxes without optional setting. This is due to the 'transparent'
being the default and the colour the optional choice.

Altered it so the colour is the default and choosing 'transparent' is
the optional choice for backwards compatibility.

Change-Id: I76e4f2f9557f3f3b8d3baf13cd35ac95d05618f2
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 3fd420f9
......@@ -34,7 +34,7 @@ $string['element.files.addattachment'] = 'Add attachment';
$string['element.select.other'] = 'Other';
$string['element.color.custom'] = 'Customise';
$string['element.color.transparent'] = 'Transparent or ';
$string['rule.before.before'] = 'This cannot be after the field "%s"';
......
......@@ -34,14 +34,14 @@ function pieform_element_color(Pieform $form, $element) {
var {$baseid}_oldval = '';
function {$baseid}_toggle(x) {
if ( x.checked ) {
$('{$baseid}').value = {$baseid}_oldval;
$('{$baseid}').disabled = false;
}
else {
{$baseid}_oldval = $('{$baseid}').value;
$('{$baseid}').value = '';
$('{$baseid}').disabled = true;
}
else {
$('{$baseid}').value = {$baseid}_oldval;
$('{$baseid}').disabled = false;
}
}
</script>
EOF;
......@@ -52,18 +52,18 @@ EOF;
}
$optional .= ' <input type="checkbox" '
. (isset($element['defaultvalue']) && $element['defaultvalue'] == 'transparent' ? '' : 'checked="checked" ')
. (isset($element['defaultvalue']) && $element['defaultvalue'] == 'transparent' ? 'checked="checked" ' : '')
. 'name="' . $name . '_optional" id="' . $baseid . '_optional" onchange="' . $baseid . '_toggle(this)" '
. 'tabindex="' . Pieform::hsc($element['tabindex']) . '">';
$optional .= ' <label for="' . $baseid . '_optional">'
. $title . $form->i18n('element', 'color', 'custom', $element) . '</label> ';
. $title . $form->i18n('element', 'color', 'transparent', $element) . '</label> ';
$result .= $optional;
}
// Color Picker (Chooser)
$result .= '<input type="text" name="' . $name . '_color" id="' . $baseid . '"'
. ($transparent && !isset($element['defaultvalue']) ? ' disabled="disabled"' : '')
. ($transparent && (!isset($element['defaultvalue']) || $element['defaultvalue'] == 'transparent') ? ' disabled="disabled"' : '')
. ($transparent ? ' class="color {hash:true,required:false}"' : ' class="color {hash:true}"')
. ' value="' . ($value == 'transparent' ? '' : $value) . '">';
......@@ -80,7 +80,7 @@ EOF;
function pieform_element_color_get_value(Pieform $form, $element) {
$name = $element['name'];
$global = ($form->get_property('method') == 'get') ? $_GET : $_POST;
if ($form->is_submitted() && isset($global[$name . '_color']) && isset($global[$name . '_optional'])) {
if ($form->is_submitted() && isset($global[$name . '_color']) && !isset($global[$name . '_optional'])) {
$color = $global[$name . '_color'];
// Whitelist for a 6-digit hex color
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment