Thread Starter
Endolil
(@zabdesign)
I still have this problem.
I have a set of checkboxes in my cft template and I use this custom fields for some options in my wordpress templates.
I do not understand how to make sure that checkboxes are checked or unchecked by default.
Anbody?
default=0
Like this:
[custom_field]
type=checkbox
default=0
label=Custom Field
Having the same problem, but the above solution is not working for me. I really need some checkboxes checked by default.
Thanks in advance!
Here’s a workaround.
In your template description add this:
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('.default_checked').attr('checked', true);
});
</script>
Remember you can any script into your template description field. I use it to attach css and js on a per template basis.
The following code block creates a CFT template with 3 checkboxes that will all be checked when the page loads:
[test]
type= checkbox
value = apple # orange # banana
default = orange
valueLabel = apples # oranges # bananas
label = text
class=default_checked
You could make individual checkboxes with that default_checked class applied. That will ensure that when that the only checkboxes you want are checked.
Have a nice day.
I had a little after thought.
You will need to add a check to see if the page has been loaded before, otherwise the it will recheck the default_checked checkboxes, over-riding them if the user wants them really unchecked.
Add a test to see if another field has been entered.
[anotherfield]
type = text
label = A normal cft field in your template
class = field_test
[test]
type= checkbox
value = apple # orange # banana
default = orange
valueLabel = apples # oranges # bananas
label = text
class=default_checked
Update text description area:
<script type="text/javascript">
jQuery(document).ready(function () {
if( jQuery('.field_test').val() == '' ) {
jQuery('.default_checked').attr('checked', true);
}
});
</script>
I´m not sure this is related to the problem I’m having just trying to set default boxes just like the template example.
What I found out is that the default= option seem to work only in the template #0. If I try the same config in the following templates, it doesn´t seem to work.
A bug?