I use the select2 plugin to search for cities that are taken from the server by ajax, then through the plugin I put into the form on the page something like this
<select class="form-control from" id="from"></select>
in such a script I add values to the form
$(".from").select2({ language: 'ru', theme: 'bootstrap', placeholder: "выберите город", allowClear: true, ajax: { url: "script.php", dataType: 'json', delay: 250, data: function (params) { return { q: params.term, // search term to: 'searchCity' }; }, processResults: function (data) { return { results: data }; }, }, escapeMarkup: function (markup) { return markup; }, // let our custom formatter work minimumInputLength: 1, templateResult: formatRepo, templateSelection: formatRepoSelection }); function formatRepoSelection (repo) { return repo.lable || repo.text; } function formatRepo (repo) { if (repo.loading) return repo.text; var markup = "<option value='"+ repo.code +"'>"+repo.name+"</option>"; return markup; }
When searching for values, pop-up menus are filled in, but when I click on any item in the list, nothing happens, the form does not respond, what am I doing wrong?
outliers cannot be selected
upd2: here is the server response
[{"label":"\u041c\u043e\u0441\u043a\u0432\u0430, \u0420\u043e\u0441\u0441\u0438\u044f (MOW)","code":"MOW","name":"\u041c\u043e\u0441\u043a\u0432\u0430"},{"label":"\u041c\u043e\u0441\u0442\u0430\u0440, \u0411\u043e\u0441\u043d\u0438\u044f \u0438 \u0413\u0435\u0440\u0446\u0435\u0433\u043e\u0432\u0438\u043d\u0430 (OMO)","code":"OMO","name":"\u041c\u043e\u0441\u0442\u0430\u0440"},{"label":"\u041c\u043e\u0441\u044c\u043e\u0435\u043d, \u041d\u043e\u0440\u0432\u0435\u0433\u0438\u044f (MJF)","code":"MJF","name":"\u041c\u043e\u0441\u044c\u043e\u0435\u043d"},{"label":"\u041c\u043e\u0441\u0441\u043e\u0440\u043e, \u0420\u0438\u0443-\u0413\u0440\u0430\u043d\u0434\u0438-\u0434\u0443-\u041d\u043e\u0440\u0442\u0438, \u0411\u0440\u0430\u0437\u0438\u043b\u0438\u044f (MVF)","code":"MVF","name":"\u041c\u043e\u0441\u0441\u043e\u0440\u043e"},{"label":"\u041c\u043e\u0441\u043a\u0443\u0435\u0440\u0430, \u041a\u043e\u043b\u0443\u043c\u0431\u0438\u044f (MQR)","code":"MQR","name":"\u041c\u043e\u0441\u043a\u0443\u0435\u0440\u0430"}]