Default values not working on select or radio fields
- This topic has 3 replies, 2 voices, and was last updated 2 years, 12 months ago by
Long Nguyen.
-
AuthorPosts
-
April 21, 2022 at 12:10 AM #35730
TGHP
ParticipantHi,
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', ], ],
April 21, 2022 at 5:12 PM #35747Long Nguyen
ModeratorHi,
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 ], ], ],
April 21, 2022 at 10:10 PM #35757TGHP
ParticipantHi 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.
April 22, 2022 at 2:26 PM #35766Long Nguyen
ModeratorHi,
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
-
AuthorPosts
- You must be logged in to reply to this topic.