I am receiving the error above with Select2 3.2 while calling select2() with the 'ajax' option
specified. I found another issues related to Select2 with a multi select widget but this is not the case here. I have multiple select elements with a pretty long option list and now I am trying to move the code to ajax.
this is a documented limitation. if you want to use ajax you have to attach to a hidden input tag.
Text field not working with select2.
@ivaynberg This does not appear to be documented anymore, at least not on the ajax examples section of the page, there is also isn't any HTML shown for the ajax example either.
I think no need to go with hidden input element. You can give a try, get plain html data from ajax call and set it in <select> and then init select2 resetting method. Here's code snippet
HTML
<select id="select" name="select" class="select2">
<option value="" selected disabled>Please Select Above Field</option>
</select>
Javascript
$.ajax({
type: "POST",
cache:false,
url: YOUR_AJAX_URL,
success: function(response)
{
$('#select').html(response);
}
});
$('#select').select2("val","");
Ajax Response :
<option value="value">Option Name</option> . . . <option value="value">Option Name</option>
@ivaynberg wonder if you can explainthe reason for using a hidden field for multuple + ajax?
Genuine question.
@ivaynberg wonder if you can explainthe reason for using a hidden field for multuple + ajax?
Genuine question.
@kyle-sorensen @dnagir There is more information about this issue, and how it will be fixed in Select2 4.0 in https://github.com/ivaynberg/select2/issues/279.
I met this problems too, I want to know why
What a stupid "me too, me too"...
@zopyx HaHa, I have give up that way
@zopyx LOL go fuck yourself.
Most helpful comment
@zopyx LOL go fuck yourself.