-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Mulitple on post select shows multiple selections on edit #428
Comments
@Arcath thanks for taking the time to submit a ticket! Can I ask why you want multiple multi-select boxes in an edit screen? I'm kind of thinking that we might want to just disable this option for multi-select since it inherently has this option, but if there's a good use case I'm open to finding ways around this bug. Also, do you mean |
@mikeselander I only want the one select box. It works as expected with no data letting me add X pages before saving the page. Once I save and come back I get the issue. If I take out |
Ah right., I misunderstood you - apologies. I know what's causing this but will take a little bit of time to dig into and find a fix that doesn't mess something else up. |
@mikeselander For now would I better using single selections with repeatable? Just thinking then I can deliver the product |
@Arcath how soon do you need to deliver this? I might be able to carve out some time later this week since it sounds more urgent to you. |
@mikeselander I have plenty of time. We aren't looking at launching for a while yet. |
@mikeselander there is also an issue in saving that post_select multiple field. When adding multiple selection and save that post page, it displays each selection in each line like that. On updating this post page again, only first single option is selected and the rest options disabled. Is there any quick solution to fix this issue? Many thanks |
@HeartBreakKid58 I don't have an easy off the top of my head answer unfortunately. I just need to get around to fixing this. Thanks for the report! |
If anyone's stumbling upon this, I solved it by extending class PostSelectField extends \CMB_Post_Select {
/**
* Print out a field.
*/
public function display() {
if ( $this->args['use_ajax'] && $this->args['multiple'] ) {
$this->values = [ implode( ',', $this->values ) ];
}
parent::display();
}
/**
* Output inline scripts to support field.
*/
public function output_script() {
$this->value = explode( ',', $this->value );
parent::output_script();
}
} It works fine for our use case. Perhaps it needs some adjustment for yours. |
@swissspidy How do you tell CMB to use this class over |
@Arcath Use something like this: add_filter( 'cmb_field_types', function( array $fields ) {
$fields['post_select'] = PostSelectField::class;
return $fields;
} |
I have a post select field on one of my pages that uses the
multiple
option.When I edit the page to begin with it works as it should letting me select as many pages as I want.
After saving the page and coming back to edit it I get each page in its own select2 box.
All the boxes have the same id/name and only the first one gets saved.
I'm using the latest
dev-master
code.The text was updated successfully, but these errors were encountered: