WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Custom Field Template] checkbox really checked by default

[Plugin: Custom Field Template] checkbox really checked by default

  • Endolil
    Member

    @zabdesign

    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/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Endolil
    Member

    @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?

    Dalton Rooney
    Participant

    @daltonrooney

    default=0

    Like this:

    [custom_field]
    type=checkbox
    default=0
    label=Custom Field
    Icethrill
    Member

    @icethrill

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

    Thanks in advance!

    proximity2008
    Member

    @proximity2008

    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.

    proximity2008
    Member

    @proximity2008

    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.