Support Forum
Support › Meta Box Group › Default values not working on select or radio fieldsResolved
Hi,
I have used the logic provided on the group extension support page, with select and radio fields, but it is not working. Is there a different method I need to use that supports default values on select and radio fields?
https://docs.metabox.io/extensions/meta-box-group/#setting-default-group-values
[
'id' => 'block_cross_linking_cards',
'name' => 'Cards',
'type' => 'group',
'clone' => 'true',
'sort_clone' => true,
'collapsible' => true,
'default_state' => 'collapsed',
'group_title' => ['field' => 'block_cross_linking_cards_title'],
'add_button' => '+ Add Card',
'fields' => [
[
'id' => 'block_cross_linking_cards_style',
'name' => 'Card style',
'type' => 'select',
'options' => [
'card' => 'Card',
'image-background' => 'Image Background',
],
],
],
'std' => [
'block_cross_linking_cards_style' => 'card',
],
],
Hi,
Thanks for your feedback.
The default subfield value does not work with the cloneable group and under the group settings. But you can use the subfield setting to set the default value. Like this
[
'id' => 'block_cross_linking_cards',
'name' => 'Cards',
'type' => 'group',
'clone' => 'true',
'sort_clone' => true,
'collapsible' => true,
'default_state' => 'collapsed',
'group_title' => ['field' => 'block_cross_linking_cards_title'],
'add_button' => '+ Add Card',
'fields' => [
[
'id' => 'block_cross_linking_cards_style',
'name' => 'Card style',
'type' => 'select',
'options' => [
'card' => 'Card',
'image-background' => 'Image Background',
],
'std' => 'card' //here
],
],
],
Hi Long,
Thanks for your response.
I had originally used the single 'std' arg on the subfield setting, exactly as you've shown above, but unfortunately that didn't work either. The select/radio fields are blank until you actively select the option, so no default value is ever set when the post is updated. I believe this is a bug of the group field.
Hi,
I see it works as well on my site, if you want to set the default value for the subfield in clone, please use the setting clone_default
https://monosnap.com/file/t85mnXYKJ0DRr7htpGMZ7DLzsSLppN
[
'id' => 'block_cross_linking_cards',
'name' => 'Cards',
'type' => 'group',
'clone' => 'true',
'sort_clone' => true,
'collapsible' => true,
'default_state' => 'collapsed',
'group_title' => ['field' => 'block_cross_linking_cards_title'],
'add_button' => '+ Add Card',
'clone_default' => true, //here
'fields' => [
[
'id' => 'block_cross_linking_cards_style',
'name' => 'Card style',
'type' => 'select',
'options' => [
'card' => 'Card',
'image-background' => 'Image Background',
'c' => 'C'
],
'std' => 'image-background' //here
],
],
],
Read more on this documentation https://docs.metabox.io/extensions/meta-box-group/#clone-default-values