Answer the question
In order to leave comments, you need to log in
How in Select2 (jQuery) to open and display results on an external event?
select2 remote data source
The essence is this - there is a drop-down list where options are loaded from an external database. Well, type you start to enter, and shows the options found from which you need to choose one.
I want to make it so that on an external click (on a link), the drop-down list opens and shows the results found with the request passed when clicking, so that you can select.
Let's say open is just $('#select_id').select2("open"); but how to insert text into the open and force it to search - I can’t think of it
jsfiddle.net/marcrazyness/XMAq2 this is an example from the Internet (it takes a long time to load)
Answer the question
In order to leave comments, you need to log in
Resolved like this
function select2_search($el, term) {
$el.select2('open');
// Get the search box within the dropdown or the selection
// Dropdown = single, Selection = multiple
var $search = $el.data('select2').dropdown.$search || $el.data('select2').selection.$search;
// This is undocumented and may change in the future
$search.val(term);
$search.trigger('keyup');
}
$('button').on('click', function () {
var $select = $($(this).data('target'));
select2_search($select, 'Arizona');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question