-
Notifications
You must be signed in to change notification settings - Fork 304
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
TbSelect2 - multiselect and placeholder lead to empty selection #717
Comments
Yes, the problem is that $this->addEmptyItemIfPlaceholderDefined() is called even for multiple selects. The select2 docs say that an empty option should be added only for non-multi-value selects: "Note that because browsers assume the first option element is selected in non-multi-value select boxes an empty first option element must be provided () for the placeholder to work." So in order to fix this problem, this: $this->addEmptyItemIfPlaceholderDefined(); should be replaced with this: if (empty($this->htmlOptions['multiple'])) {
$this->addEmptyItemIfPlaceholderDefined();
} Additionally, the proper way to add an empty option as the first element is (in prependDataWithEmptyItem()): $this->data = array_reverse($this->data, true);
$this->data[''] = '';
$this->data = array_reverse($this->data, true); Otherwise the empty option is added to the end and the single-select will still show "undefined". |
Thanks for the help! I've made the changes in my project and it appears to work correctly now. Just made a Pull Request too: #719 |
I've got this TbSelect2 on a page:
When nothing is selected it always looks like this:
http://s19.postimg.org/bnx6z3xer/Tb_Select2.png
There's an empty selection box.
When I either set 'multiple'=>false or remove the 'placeholder' then it looks ok.
I guess it has to do with this in the TbSelect2 class?
Any way to get around this!?
The text was updated successfully, but these errors were encountered: