I am using Bootstrap select dropdown which has the following code.
HTML
@Html.DropDownList("Product", SelectList, new { data_live_search = "true", @class = "content-small selectpicker", @tabindex = 1 })
In this dropdown I need to provide an option to add new values which are typed in the search bar in the dropdown to the existing collection of the dropdown based on the click event. I have modified the UI to say "Create" instead of No results found. Please refer the code and UI below.
JS
$('#Product').selectpicker({ noneResultsText: 'Create ' });
UI
I am trying to add click event to this text "Create" content which is highlighted in the screenshot above to add that content dynamically to the existing collection of the dropdown.
But, while clicking that text the dropdown gets closed and the element which shows the text gets removed, hence I could not call the on click function to add this item dynamically.
What are the possibilities of using this?
I think you're skipping that the input you're dealing with is outside of the
.selectpicker
. You can find working snippet below.