Forum
Templates - default attribute fault
I am using a checkbox control to show/hide content with Perch.
eg.
<perch:if exists="show">
content
</perch:if>
<perch:content type="checkbox" value="1" suppress="true" id="show" label="Show content" default="1" />
Unfortunately, the default
attribute causes the box to be checked in Perch UI whenever I revisit the region, regardless of the state it should be. I.e. if I uncheck and save, the box ticks itself again.
Without the default
attribute, the checkbox functions as expected.
Perch v2.6
The
default
attribute is used for a field whenever it's blank, so it doesn't really make sense for a checkbox.Ok, is there a way of giving the checkbox a default value, without breaking it?
How would that work, conceptually? I just don't think it makes sense with checkboxes.
By 'default value', I mean checked or unchecked.
Normally, when an editor creates a new item in the region, they'll want the content to show, so the box should be checked already. If they decide not to show the content they would uncheck the box. This is an opt-out situation and is most convenient for the editor.
In other regions, it might be preferential to have to opt-in to showing content instead. Certainly in my case this is less likely, but is how
<perch:content type="checkbox" ... />
behaves without modification.All the checkbox knows is if it's checked or not. I has no way of seeing if it was checked in the past or anything like that.
I'm not sure you understand what I mean.
All I'm asking about is when a editor creates a new region item, can the checkbox be checked by default?. Just like the way
<input type="checkbox" checked="checked">
behaves.As the editor is far more likely to want it checked, it would be helpful if they wouldn't have to tick it themselves. Seems petty, but I don't feel it's professional if they have to tick the box for the vast majority of items they add, and it could get annoying.
See my original post on the simple content template I am trying to write for this situation.
Thanks.
I understand.
That's the issue.
Yup, I understood from your first reply that
default
is now the wrong attribute to use here.It doesn't sound like there is a way of doing this. Perhaps it's something you can look at for a future version?
In my situation, I think I will change the box's function to hide content if checked. Do I have to write this as:
or is there a more direct way of asking if a field does not exist?
Thanks
Thank you