Forum
Bug or just illogical behaviour?
Hi, not sure if this is a bug or not?
I've got a template with a checkbox included, giving editors the option to show/hide a certain part of the page. By default it's ticked to show the section and I've done this using the default attribute (default="1").
But, when an editor un-ticks the box, it does save and hides the section - but the next time they visit that page to edit another part of it - it's checked again meaning the section is unknowingly re-published.
Is there a better way to achieve this other than default, or is it a bug?
We need to see your template to advise.
The checkbox causing the problem is this line in the below template:
Full template:
Checkboxes are deceptively complex. They only have a value when they're checked - there's no negative value. So when repopulating the field, if the
value
attribute matches what we have stored for the checkbox, it gets checked.If there's no value set, we use the default, as you'd expect.
The issue comes when you've unchecked the box - it has no value - so we use the default. That's what you're seeing.
A workaround might be to use a Yes/No select box.
Thanks Drew
I kinda guessed it would be down to the genuine awkwardness that is the ever popular checkbox!
A yes/no select seems like a relatively straightforward replacement.
Thanks :)