Page 1 of 1

[fixed] News: checkboxes (extra fields) do not get unset

Posted: Mon Aug 17, 2015 10:24 am
by olreti
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.

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} />
Shouldn't that perhaps read

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} />
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

Re: News: checkboxes of extra fields do not get unset

Posted: Mon Aug 17, 2015 11:36 am
by archeo
I confirm : an unchecked checkbox is not saved correctly.

Re: [confirmed] News: checkboxes (extra fields) do not get u

Posted: Mon Aug 17, 2015 3:09 pm
by olreti
Thanks for confirming.
Unfortunately, my version doesn't work correctly either, now newly set checkboxes are not saved. Does anyone see the correct way? :)

Re: [confirmed] News: checkboxes (extra fields) do not get u

Posted: Tue Aug 18, 2015 12:53 am
by calguy1000
That was an easy fix (minor change in a template). Fix will be available in the next snapshot.

Re: [fixed] News: checkboxes (extra fields) do not get unset

Posted: Tue Aug 18, 2015 8:07 am
by archeo
For me it is OK on snapshot 2015-08-18 00:30

Re: [fixed] News: checkboxes (extra fields) do not get unset

Posted: Tue Aug 18, 2015 10:38 am
by olreti
Can confirm as well, works now.
Thanks, guys.