• Hey,

    I am wondering if it is possible to create a checkbox in the custom field template which is checked by default.

    I am suing this code:

    [Show Text]
    type = checkbox
    value = true
    default = true
    valueLabel = yes
    label = Show this field?

    … but I never get a checked checkbox when I load the template! What am I doing wrong? I tried many different combinations but I do not get it to work.

    Regards,
    Sebastian

    https://www.ads-software.com/extend/plugins/custom-field-template/

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Custom Field Template] checkbox really checked by default’ is closed to new replies.