Support › MB Custom Table › Custom Table - Group NULLResolved
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
MB_Custom_Table_API::create( 'my_custom_table', array( 'address' => 'TEXT NOT NULL', 'phone' => 'TEXT NOT NULL', 'email' => 'VARCHAR(20) NOT NULL', ) );
$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.
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 🙂