Custom Table - Group NULL

Support MB Custom Table Custom Table - Group NULLResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #12145
    davidrknowlesdavidrknowles
    Participant

    Not sure if this is purposefully like this or is a bug but if you use a group for the custom table column key like this

    Custom Table

    MB_Custom_Table_API::create( 'my_custom_table', array(
        'address' => 'TEXT NOT NULL',
        'phone'   => 'TEXT NOT NULL',
        'email'   => 'VARCHAR(20) NOT NULL',
    ) );

    Metabox

    $meta_boxes[] = array(
        'title'        => 'Meta Box Title',
        'storage_type' => 'custom_table', 
        'table'        => 'my_custom_table',
        'fields'       => array(
            array(
                'name'        => 'Address',
                'id'          => 'address',
                'type'        => 'group',
                'fields'       => array(
                    array(
                        'name'        => 'Line 1',
                        'id'          => 'line_1',
                        'type'        => 'text',
                    ),
                    array(
                        'name'        => 'Line 2',
                        'id'          => 'line_1',
                        'type'        => 'text',
                    ),
                 ),
            ),
            array(
                'name'        => 'Phone',
                'id'          => 'phone',
                'type'        => 'text',
            )
        )
    );

    Now if none of the group fields are filled out it returns NULL when saving in the DB, not sure if this is the intent and it easily can be altered by creating the table not using NOT NULL, but thought I would flag it in case as none of the other fields have this behaviour on saving.

    Also it might be value adding to the docs that the baseline field ids have to match the table column key, and that the group id is required if nesting the fields in groups.

    #12157
    Anh TranAnh Tran
    Keymaster

    Hi David,

    Thanks a lot for your feedback.

    When you submit a post, the Group has a mechanism to filter all the sub-fields' values to remove empty values (to save space). So, if no value is entered, that means the group doesn't have any value. I'll check why it saves NULL in the DB.

    I also updated the MB Custom Table docs to include your points. Thanks for helping 🙂

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