'Switch' Custom Field Element Cannot be Defaulted to "On"

Support MB Custom Post Type 'Switch' Custom Field Element Cannot be Defaulted to "On"Resolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #47436
    CodogCodog
    Participant

    Hi there,
    I recently wanted to use the 'Switch' element in a custom post type as documented here: https://docs.metabox.io/fields/switch/.

    I added a switch element to my array of custom fields like this:

    [
    'id'        => 'enable_switch',
    'name'      => 'Enable This',
    'type'      => 'switch',
    'style'     => 'square',
    'on_label'  => 'Enabled',
    'off_label' => 'Disabled',
    'std'   => true,
    ],

    However, the 'std' => true, attribute is never respected to default the switch to an "on" status. This attribute is what is used by your Metabox builder as the "ON by Default" PHP output.

    I have also tried a range of other permutations such as 'std' => 1, OR 'std' => 'Enabled', but none of these seem to work either?

    Is this a bug? Or am I unaware of the correct method to default the switch to an "on" status?

    I look forward to your response.

    #47449
    PeterPeter
    Moderator

    Hello,

    I recheck this setting of the switch field on my site and see that it still works correctly. Can you please share all the field group code so I can add it to my site and check the issue?

    #47450
    CodogCodog
    Participant

    Hi Peter,
    thanks for getting back to me. After further investigation and testing, It looks like this issue was a false positive and related to a transient. The switch works as expected with the 'std' => true, attribute. My bad! This can be closed.

    #47453
    CodogCodog
    Participant

    Hi Peter,
    I have found an additional condition where 'std' => true, for the Switch element is not respected in Metabox Group Subfield clones. Please see this ticket: https://support.metabox.io/topic/switch-element-cannot-be-defaulted-to-on-within-mb-group-clones/. Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.