WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Custom Field Template] checkbox really checked by default (7 posts)

  1. endolil
    Member
    Posted 4 years ago #

    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

    http://wordpress.org/extend/plugins/custom-field-template/

  2. endolil
    Member
    Posted 4 years ago #

    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?

  3. Dalton
    Member
    Posted 3 years ago #

    default=0

    Like this:

    [custom_field]
    type=checkbox
    default=0
    label=Custom Field
  4. Icethrill
    Member
    Posted 3 years ago #

    Having the same problem, but the above solution is not working for me. I really need some checkboxes checked by default.

    Thanks in advance!

  5. proximity2008
    Member
    Posted 3 years ago #

    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.

  6. proximity2008
    Member
    Posted 3 years ago #

    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>
  7. Decio
    Member
    Posted 3 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic