Custom Fields
Re-Envisioned
Support Meta Box Group [Request] Force number of clones

This topic contains 3 replies, has 2 voices, and was last updated by  Anh Tran 1 year, 10 months ago.

  • Creator
    Topic
  • #6616
    Resolved
    brandoo
    Participant

    Hi

    Can we add a option to force number of clones? So there will be always a fixed number of clones from the start and user will be able only to rearrange them?

    Right now I can only set the max limit of clones and there is no way to change order of separate fields.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #6623

    Anh Tran
    Keymaster

    Hi,

    Yes, you can do that by specified the std value. This code will set the 3 inputs (clones):

    array(
        'type' => 'text',
        'id' => 'test',
        'clone' => true,
        'max_clone' => 3,
        'std' => array( '', '', '' ) // Default values for 3 clones
    )
    #6634

    brandoo
    Participant

    Yes but it seams to only work with separate fields (not whole groups) and you still can remove or add more copies.

    #6644

    Anh Tran
    Keymaster

    If you need to make for groups, you can set std as array of arrays of default values for sub fields, like:

    $default_for_group = array( '', '', '' ); // sub field 1, 2, 3
    'std' => array( $default_for_group, $default_for_group, $default_for_group ),

    To prevent users from removing clones, you can hide them with CSS. A simple trick is adding a custom_html field to output styles, like this:

    array(
        'type' => 'custom_html',
        'std' => '<style>.rwmb-group-wrapper .remove-clone { display: none; }</style>
    )

    You might want to add custom class to your group fields, so the CSS selector is more specific.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.