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

Forum rules
Only administrators can post or move items here.
Post Reply
olreti
New Member
New Member
Posts: 3
Joined: Sat Oct 18, 2014 6:39 am

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

Post 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
Last edited by olreti on Mon Aug 17, 2015 12:09 pm, edited 1 time in total.
archeo
Forum Members
Forum Members
Posts: 104
Joined: Tue Oct 21, 2014 12:47 pm
Location: Lorient (France)

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

Post by archeo »

I confirm : an unchecked checkbox is not saved correctly.
olreti
New Member
New Member
Posts: 3
Joined: Sat Oct 18, 2014 6:39 am

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

Post 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? :)
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

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

Post by calguy1000 »

That was an easy fix (minor change in a template). Fix will be available in the next snapshot.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
archeo
Forum Members
Forum Members
Posts: 104
Joined: Tue Oct 21, 2014 12:47 pm
Location: Lorient (France)

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

Post by archeo »

For me it is OK on snapshot 2015-08-18 00:30
olreti
New Member
New Member
Posts: 3
Joined: Sat Oct 18, 2014 6:39 am

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

Post by olreti »

Can confirm as well, works now.
Thanks, guys.
Post Reply

Return to “Closed Issues”