Forum

Thread tagged as: Problem, Error

Checkbox default attribute bug?

Hi there,

It seems that setting the default attribute of a checkbox to 1 makes it forever stay checked, rather than just as a default. After unchecking it, it simply becomes checked again upon saving the region. I noticed this a couple of years ago using Perch, problem still seems to be there. Can you replicate this?

Thanks,

Alex

Digital Team

Digital Team 0 points

  • 6 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Can we see your template?

<perch:content type="checkbox" default="1" suppress="true" id="show_2_cols" label="Show Two Column Layout?" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

It's quite a complex issue. In HTML, when a checkbox has no value the field simply doesn't exist in the data that is sent from the form. There is therefore no difference between an unchecked checkbox and a checkbox which hasn't been checked yet.

I've just run into this - is there any way for Perch to ignore the default coded in the template if the region has just been edited, as opposed to just created? Maybe querying whether there's an undo level available?

That way when you first enter something into a brand-new region, your checkbox defaults would kick in and show the ticks. But if you were editing an already-populated region, the defaults would be ignored and your choice of having a given checkbox be un-ticked could be shown in the UI.

No idea if Perch's guts could allow for that, but what do you reckon?

I had the same issue with the following code

type="checkbox" value="yes" default="yes"

Changing it to

type="checkbox" value="yes" default="checked"

seems to have helped