Re: CMB2 'Group' field type support
Hi,
I'm currently working on a custom menu block for the gridder.
Right now I'm using a CMB2 Gorup field which contains a "label" (input_type: text), an "URL" (input type: text_url) and a "Open in new page" (input_type; checkbox) in order to create a menu element.
The group field and types get retrieved correctly from the model but val is always false or undefined
This is the Setup
$cmb = new_cmb2_box(array(
'id' => 'nfl_metabox',
'title' => 'Inner navigation menu'
));
$group_field_id = $cmb->add_field( array(
'id' => 'nfl_links',
'type' => 'group',
'description' => __('Generates reusable form entries', 'cmb2'),
'options' => array(
'group_title' => __('Entry {#}', 'cmb2'),
'add_button' => __('Add Another Entry', 'cmb2'),
'remove_button' => __('Remove Entry', 'cmb2'),
'sortable' => true,
),
));
$cmb->add_group_field($group_field_id, array(
'name' => 'Link label',
'id' => 'label',
'type' => 'text',
));
$cmb->add_group_field($group_field_id, array(
'name' => 'Link URL',
'id' => 'url',
'type' => 'text_url',
));
$cmb->add_group_field($group_field_id, array(
'name' => 'Open in new tab',
'id' => 'new_tab',
'type' => 'checkbox',
));
And this is the rendering
console.log(model);
var viewContent = '';
var viewElement = document.createElement('div');
var wrapperElement = document.createElement('ul');
var links = model.get('nfl_links').val;
[...links].forEach(link => {
var menuElement = document.createElement('li');
menuElement.innerHTML = link.label.val;
wrapperElement.appendChild(menuElement);
})
return wrapperElement.innerHTML;
Thank you in advance!
Update
I noticed that even with a checkbox outside the CMB2 group I always get false as a result