[fixed] News: checkboxes (extra fields) do not get unset
Posted: Mon Aug 17, 2015 10:24 am
Hey everyone, can somebody please verify the following:
If I add an extra field of type "checkbox" to the news module and modify the article, the new value (1) is saved correctly if the checkbox had previously been unselected.
But if I edit it again and I remove the check, it is back to being checked after submitting the form.
Expected behaviour, of course, being that it unsets.
This appears to be related to these lines in news/templates/editarticle.tpl, where (to my understanding) a hidden entry of the same name as the checkbox is used to always include it in $POST, as browsers normally only send it if it's true.
Shouldn't that perhaps read
or something similar? (Sorry, can't highlight in code patterns, it seems. Look at the parameters of 'value' in each row.)
All the best
T
If I add an extra field of type "checkbox" to the news module and modify the article, the new value (1) is saved correctly if the checkbox had previously been unselected.
But if I edit it again and I remove the check, it is back to being checked after submitting the form.
Expected behaviour, of course, being that it unsets.
This appears to be related to these lines in news/templates/editarticle.tpl, where (to my understanding) a hidden entry of the same name as the checkbox is used to always include it in $POST, as browsers normally only send it if it's true.
Code: Select all
{elseif $field->type == 'checkbox'}
<input type="hidden" name="{$field->nameattr}" value="{$field->value}" />
<input type="checkbox" id="{$field->idattr}" name="{$field->nameattr}" value="1"{if $field->value == 1} checked="checked"{/if} />
Code: Select all
{elseif $field->type == 'checkbox'}
<input type="hidden" name="{$field->nameattr}" value="false" />
<input type="checkbox" id="{$field->idattr}" name="{$field->nameattr}" value="{$field->value}"{if $field->value == 1} checked="checked"{/if} />
All the best
T