Skip to content

Destroying and Reinitializing a selectpicker with title generates an empty option at index 0 #2491

@Slowey

Description

@Slowey

Environment:
Boostrap 4
Boostrap-select 1.13.17
jQuery version 3.4.1
Windows 10
Chrome 83.0.4103.97

I've been trying to dynamically change my bootstrap-select dropdown between multiselect and singleselect using javascript.
My way of going about this has been to remove/add the attribute multiple to my select element and then reinitialize the selectpicker component (selectpicker.destroy + selectpicker).
This leads to a bug were an extra option is added when switching from single select to multi select. It seems to have something to do with the title attribute. If the title attribute is empty string or the title attribute is not set this problem does not occur.

I have created a plunker demo below with a single select list with only 1 option and a button that toggles the code I wrote to switch between single/multi-select:
https://plnkr.co/edit/DwR6cCzLigExMpH6?preview

Try clicking the button a couple of times, try reloading the site and removing the title attribute.

Is this the wrong way to go about my problem? Is there another better solution to switch between multi/single-select during runtime?

BR,
Lucas

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions