when using the select2 multiselect and selecting an option I get this error message displayed:
TypeError: b.dataAdapter is null
Does anyone know what this is about?
The multiselect works fine, I just wonder about this message.
EDIT:
This is my html:
<div class="form-group">
<label class="control-label col-md-12" for="participant-id">Participant
<span class="required"> * </span>
</label>
<div class="col-md-12">
<input type="hidden" name="participant_id" value=""/>
<select name="participant_id[]" multiple="multiple" class="form-control select2me participantSelector" required="required" id="participant-id">
<option value=""></option>
</select>
</div>
</div>
this is the jquery init:
$(".select2me").select2({
placeholder:"Select",
width:"auto",
allowClear:!0
});
The data for the multiselect I get if a value is chosen in another dropdown 'projectSelector':
$('.projectSelector').on('change', function() {
var targetProject_id = $('#project-id :selected').val();
updateParticpantDropdown(targetProject_id);
});
function updateParticpantDropdown(selectedProjectId){
$.ajax({
type: "POST",
url: '/xx/projects/xx/'+ selectedProjectId,
dataType : "json",
success: function (response, status) {
if (response.result == "success"){
var data = response.data;
$(".participantSelector").empty().select2({
placeholder: "Click here to select participants",
allowClear: false,
data: data
});
}
}
});
}
Data is getting loaded into the multiselect and everythings works as expected on the screen. Just in the console I get the error messsage of
TypeError: b.dataAdapter is null
This is my json response (in short):
{
"result":"success",
"data":[
{"id":18,"text":"xx, Ana Rosa"},
{"id":17,"text":"xx, Saul"},
{"id":14,"text":"xx, Jesus"},
{"id":15,"text":"xx, Jose Sergio"},
{"id":13,"text":"xx, Guadalupe"},
{"id":12,"text":"xx, Adolfo"},
{"id":25,"text":"xx, Roland"},
{"id":16,"text":"xx, Mariela Elisa"},
{"id":11,"text":"xx, Roberto Carlos "},
{"id":19,"text":"xx, Jose Rafael"},
{"id":2,"text":"xx, Juan Carlos"}
]
}
In Chrome I get this message:
select2.full.min.js:2
Uncaught TypeError: Cannot read property 'current' of null
at HTMLSelectElement.<anonymous> (select2.full.min.js:2)
at HTMLSelectElement.dispatch (jquery.min.js:3)
at HTMLSelectElement.r.handle (jquery.min.js:3)
at Object.trigger (jquery.min.js:3)
at HTMLSelectElement.<anonymous> (jquery.min.js:3)
at Function.each (jquery.min.js:2)
at n.fn.init.each (jquery.min.js:2)
at n.fn.init.trigger (jquery.min.js:3)
at d.select (select2.full.min.js:1)
at d.select (select2.full.min.js:2)
Since selector2 elements tend to store some additional data, I've noticed when the data of the list element is cleared in addition to $(".participantSelector").empty()
the error is gone. So, try it out this way:
var selector = $(".participantSelector");
selector.empty();
selector.removeData();
selector.select2({
placeholder: "Click here to select participants",
allowClear: false,
data: data
});
Hopefully, it works for you too.
you should remove .empty() and use like below. it is working fine for you..
$(".participantSelector").select2({
placeholder: "Click here to select participants",
allowClear: false,
data: data
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With