I am using data-live-search = "true"
And its working perfectly.
I need something like, when noneResultsText is returned, to append button on that, that will add that new result(that is not in options) as new option
Is it possible ? :)
And is it possible to have click event on start of opening select.
I wont to populate select when click is fired.
Populate it by ajax. That may be slow, i don't know yet
I can add 'open' class and open select, but i need event when is clicked on that DIV mask.
I am not shure how smart is to manualy trigger change event on select
There is a third-party plugin to populate by ajax, but I don't think there is an option right now to display a button at the end of the search. There is an issue #699 to add events, so we could add an event when no result exist for the particular search query.
@kidach the third party plug he's talking about is this one
I wrote it so let me know and have any issues with it, make sure to let me know on that repo.
i use noneResultsText to add button link and create function for on click
$('.selectpicker').selectpicker({
noneResultsText: 'I found no results <a href="" onclick=(new_client_select()) > Add New Client</a>'
});
Closing this in favor of #990. While slightly different functionality, it will be easy enough to implement both at the same time.
i use noneResultsText to add button link and create function for on click
$('.selectpicker').selectpicker({ noneResultsText: 'I found no results <a href="" onclick=(new_client_select()) > Add New Client</a>' });
Your idea really helped me
Here is my code
$('.selectpicker').selectpicker({
noneResultsText: 'No result found <button class="btn btn-light" onclick=(add_opt(this))>Add new option</button>'
});
function add_opt(event){
var value = $(event).parents('div').siblings('.bs-searchbox').find('input').val();
$(event).parents('div').siblings('.selectpicker').append($("<option></option>").text(value)).val(value);
$('.selectpicker').selectpicker('refresh');
}
Most helpful comment
i use noneResultsText to add button link and create function for on click