Hello,
this is the first time that i use “Select2”.
I have a select like this:
<select name="models" id="models> <option></option> <option id="single-model-2601" value="2601">Samsung G928F Galaxy S6 Edge Plus</option> <option id="single-model-2712" value="2712">Samsung G930F Galaxy S7</option> <option id="single-model-2713" value="2713">Samsung G935F Galaxy S7 EDGE</option> <option id="single-model-2872" value="2872">Samsung G950 Galaxy S8</option> </select>
with this javascript code:
`
// In your Javascript (external .js resource or tag)
jQuery(document).ready(function() {
jQuery("#models").select2({
minimumInputLength: 2,
placeholder: "please select model",
templateResult: formatModels
});
function formatModels (state) {
if (!state.id) {
return state.text;
}
var originalOption = jQuery(state.element);
var $state = jQuery('<div class="device-cantainer<span>'+ state.element.id + '</span><span>' + state.txt + '</span></div>');
return $state;
};
});
`
All works fine!
I have only one question about search function:
for example i have to search the phone “Samsung G950 Galaxy S8”;
in search field if i write “Galaxy s8” or “s8” or “g950” it works,
but if i write “Samsung s8” it doesn’t work … i think because words are not consecutive.
Is it possible to solve?
Thank you.
ps. I congratulate the developers for the excellent script.