Skip Navigation

[Resolved] CRED edit post form to display generic checkboxes field from new post form

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to check one of my generic checkboxes fields by default.

Solution:
Use the "default" attribute in your field configuration definition to specify the value(s) that should be checked by default.

[cred_generic_field field='mycheckboxes' type='checkboxes' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":["123"],
"options":[
{"value":"123","label":"abc"},
{"value":"234","label":"def"}
]
}

[/cred_generic_field]
Relevant Documentation:

This support ticket is created 7 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by markL 7 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#540856

Hi there,

Is there a way to set the state of a generic checkboxes field option to checked?

Something like

{"value":"1", "label":"Option 1", "checked":"1"}

?

Thanks - Mark

#541140

Hi, the checked item is not defined in your list of options, instead it is defined by the "default" attribute in the generic field:

[cred_generic_field field='mycheckboxes' type='checkboxes' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":["123"],
"options":[
{"value":"123","label":"abc"},
{"value":"234","label":"def"}
]
}
[/cred_generic_field]

In this case, the "abc" checkbox will be automatically checked. If you use the GUI to set up a custom field, you can select the default checked value in the options area.

#541345

Hi Thanks Christian,

Wow that would have saved me a lot of time. I actually solved the problem myself using an AJAX call and post meta I created with info about the fields rendered on the original form and their state at save time.

I would love to be able to find documentation for these sort of things. For example, can you point me to where the attributes for the CRED generic field are explained? I suppose the default attribute is really the only one that I needed help with.

Thanks again,
Mark

#541400

Hi, you can find documentation about CRED shortcodes here:
https://toolset.com/documentation/user-guides/cred-shortcodes/

A good general launchpad for reference material and documentation can be found here, including links to shortcode details and programmer references:
https://toolset.com/documentation/

#541419

Hi Christian,

Thanks for taking the time to reply. I have to say that I did look at the two links you posted above before submitting my support request. I couldn't find anything more about cred generic checkboxes fields than what's here:

https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field

The example there doesn't say a word about any of the parameters that can be set.

There are many support requests from people not understanding that they have to save the generic field data to the DB themselves, there is some confusion about checkbox and checkboxes fields, and there were a flurry of support requests about a bug where boxes were all checked by default around mid 2016, however I didn't find anything about how to render a checkbox checked.

I really do appreciate the support and I may have overlooked where in the documentation this is spelled out. If so please put me out of my misery.

Thanks again,
Mark.