Closed Shaatarn closed 8 years ago
Hi,
I had the same issue, fixed it with a little trick :
add_action('cmb2_init', 'foo_register_metaboxes');
function foo_register_metaboxes()
{
$select2_obj = new PW_CMB2_Field_Select2();
$select2_obj->setup_admin_scripts();
$cmb = new_cmb2_box([
'id' => 'foo-metabox',
'title' => 'foo',
'object_types' => ['post'],
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
]);
$cmb->add_field([
'name' => 'Foo Field',
'id' => 'foo_field',
'type' => 'select',
'repeatable' => true,
'attributes' => ['class' => 'pw_select2 pw_select'],
'options' => ['','x','y','z']
]);
// ...... blah, blah, blah
}
Although it's not the solution we are looking for! I hope the problem be solved in the next versions.
Thank you all A. Mirick
Same problem here. Version 2.0.4 works without problems
Same problem. Not sure how to apply the fix from @alfredomirick to the multi-select field.
Figured out getting it to work on a multiselect
$cmb_box->add_field( array(
'name' => 'Featured Authors(Users)',
'id' => $prefix . 'featured_authors',
'desc' => 'Select users. Drag to reorder.',
'type' => 'select',
'attributes' => [
'class' => 'pw_select2 pw_multiselect',
'multiple' => 'multiple',
'style' => 'width: 99%',
],
'options_cb' => 'custom_get_users_cb',
) );
Sadly it seems like the drag and drop reordering was removed from select2 version 4.* Guess I should just use the older version of this field type because I need reordering.
To get this to work you need to add this lines to functions "render_pw_select" and "render_pw_multiselect" in cmb-field-select2.php file after $this->setup_admin_scripts()
:
if ( version_compare( CMB2_VERSION, '2.2.2', '>=' ) ) {
$field_type_object->type = new CMB2_Type_Select( $field_type_object );
}
Yep, completely broken with CMB2 v2.2.2.1 + Select2 v3.0.0. None of the hacks work for me - any news on a proper fix? Have downgraded for now.
Can you test the field with version 3.0.1 and let me know if you have any further trouble.
That seems to work, thanks. Maybe an issue with the width but I think that's my custom theming. Functionally good.
@gyrus Where are you using the field? I noticed the width was off when used on the user profile editor. For now you can try passing through a min-width
like so:
$team_meta_box->add_field( array(
'name' => __( 'Team', 'iweb' ),
'id' => $prefix . 'team',
'type' => 'pw_select',
'options' => iweb_get_cmb_options_array( array( 'post_type' => 'team' ) ),
'attributes' => array(
'style' => 'min-width: 400px;',
),
) );
It's on a post edit screen. Having to manually pass an inline style each time seems a bit sub-optimal, as they say. Actually I guess the width is technically the width of the longest term, but the 'x' isn't accounted for. You can read all the terms when you see the drop-down, but the selected term isn't completely readable if it's the longest (see screenshot).
Maybe this is more about simply allowing a bit more space there?
I see what you mean. This feels like it needs raising upstream with Select2. In the meantime, if this can be fudged with CSS, there is already a CSS file included with this field which overrides a few Select2 properties. I'd be happy to accept a PR if you fancy working on this.
Cool - obviously not critical so I'll keep it pending and hopefully have a look soon :)
Awesome, thanks for sorting this issue out Phil.
Hi Phil,
Yesterday I updated CMB2 to version 2.2.2.1 and it broke the pw_select drop down. I am doing two different callbacks to populate these drop-downs and neither of them are now working. The first grabs a list of all published posts and the second grabs a list from an array in a PHP settings file. I have pasted the code below. I also updated this plugin to 3.0.0, but no joy. Can you take a look and let me know a fix for his please.
Get the post list:
`
`
and to get the array from the settings file:
`
`
which calls:
`
`
I have downgraded to CMB2 v2.2.1 and Select2 v2.0.4 and the above code works fine.
Love the plugin by the way, it has been working super well for ages now, so I am not sure what has changed in CMB2 to break it.
Thanks in advance! Shaa.