Custom Fields
Re-Envisioned
Support General "Special Field Type" to group fields?

  • Creator
    Topic
  • #10674
    nfyp145
    Participant

    Hi Tran

    If possible, I’d like to request a field to group other fields.

    Similar to “Fieldset Text” – not only for “Text”, but also for all other fields.

    
    array(
        'id'     => 'my_content',
        'name'   => 'My Content',
        'type'   => 'fieldset_for_all_field_types',
        'fields' => array(
            array(
                'id'   => 'title',
                'name' => 'Title',
                'type' => 'text',
            ),
            array(
                'id'   => 'subtitle',
                'name' => 'Subtitle',
                'type' => 'textarea',
            ),
            array(
                'id'   => 'image',
                'name' => 'Image',
                'type' => 'image',
            ),
            array(
                'id'   => 'content',
                'name' => 'Content',
                'type' => 'wysiwyg',
            ),
        ),
    ),
    

    There is a framework (Codestar Framework) supporting such field type – Codestar Framework – Fieldset

    Thanks much and looking forward to hearing back your opinion.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Author
    Replies
  • #10681
    Anh Tran
    Keymaster

    Hi,

    Have you tried Meta Box Group? It’s the group field type, and supports all kind of sub-fields, including sub-groups. And it’s cloneable (repeatable).

    #10684
    nfyp145
    Participant

    Of course, I’m using “Meta Box Group” to group different fields. It works well so far.

    
    array(
        'id'          => 'my_content',
        'collapsible' => true,
        'group_title' => 'My Content',
        'type'        => 'group',
        'fields' => array(
            array(
                'id'   => 'title',
                'name' => 'Title',
                'type' => 'text',
            ),
            array(
                'id'   => 'subtitle',
                'name' => 'Subtitle',
                'type' => 'textarea',
            ),
            array(
                'id'   => 'image',
                'name' => 'Image',
                'type' => 'image',
            ),
            array(
                'id'   => 'content',
                'name' => 'Content',
                'type' => 'wysiwyg',
            ),
        ),
    ),
    

    But I’d like to use “Meta Box Group” for specific tasks – such like collapsible, cloneable, sortable…

    Could it be nice having a field type (only) for grouping different custom fields? That way, it’ll help reducing server load.

    Thanks again Tran!

    #10686
    Anh Tran
    Keymaster

    Do you mean just grouping fields via UI? A kind of putting them in a wrapper div, but no touch on the data and each of fields still can store value as normal?

    #10689
    nfyp145
    Participant

    Hi Tran…

    Not grouping fields via UI.

    Grouping fields (each field) under one special field. Under one roof.

    
    - main_id
        * text_field_id
        * image_field_id
        * slider_field_id
        * time_field_id
        ...
    

    That way, it’d a lot easier when naming all IDs.
    And also, the dev just needs to focus on (main_id) when getting value.

    For example,

    
    /* Post Meta Box */
    
    add_filter('rwmb_meta_boxes', 'set_post_meta_box');
    function set_post_meta_box($meta_boxes) {
        $meta_boxes[] = array(
            'id'         => 'post_meta_box',
            'post_types' => 'post',
            'tab_style'  => 'left',
            'tabs'       => array(
                'box_1_tab' => 'Box 1',
                'box_2_tab' => 'Box 2',
            ),
            'title'      => 'Post Meta Box',
            'fields'     => array(
    
                /* Box 1 */
    
                array(
                    'id'     => 'box_1',
                    'tab'    => 'box_1_tab',
                    'type'   => 'special_fieldset',
                    'fields' => array(
                        array(
                            'id'   => 'title',
                            'name' => 'Title',
                            'type' => 'text',
                        ),
                        array(
                            'id'   => 'description',
                            'name' => 'Description',
                            'type' => 'textarea',
                        ),
                    ),
                ),
    
                /* Box 2 */
    
                array(
                    'id'     => 'box_2',
                    'tab'    => 'box_2_tab',
                    'type'   => 'special_fieldset',
                    'fields' => array(
                        array(
                            'id'   => 'title', // Same ID from Box 1
                            'name' => 'Title',
                            'type' => 'text',
                        ),
                        array(
                            'id'   => 'description', // Same ID from Box 1
                            'name' => 'Description',
                            'type' => 'textarea',
                        ),
                    ),
                ),
            ),
        );
        return $meta_boxes;
    }
    

    To return values…

    
    $box_1             = rwmb_meta('box_1');
    $box_1_title       = $box_1['title'];
    $box_1_description = $box_1['description'];
    
    $box_2             = rwmb_meta('box_2');
    $box_2_title       = $box_2['title'];
    $box_2_description = $box_2['description'];
    

    Without defining long ID names for each field,
    the dev can return values for Title and Description just using box_1 and box_2 IDs.

    #10713
    Anh Tran
    Keymaster

    I got it. So your main purpose is not writing different IDs for groups.

    While this is not recommended, but I think it still works with the current version of Groups. I mean you can set the same ID for sub-fields in different groups. And then you can access to them using the same keys. It should work in most cases. Please just test it.

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