multiple initiating in Modal
Opened this issue · 0 comments
Shuraih-Usman commented
I am using it in multiples modal items, with the same class,
but each modal has it's datas, so if i open one modal, and open another onea again, then it would appeared twice, if i open another modal again it would again appeared, i used empty(); function to empty it but it does not work.
i am using it direct from ajax
<select name="category" id="edit-wish-cats" class="wide"> </select>
this is the html
` function initSelect2(id, type, pid ='') {
var selectID = $("#"+id);
let ids = '';
var isID = pid.length > 0;
if(isID) {
ids = pid;
}
if(selectID) {
$('#'+id).empty();
$.ajax({
type: 'POST',
url: ajaxURL,
headers: {
'X-CSRF-TOKEN': csrfToken
},
data: {
action : 'getselect',
type: type,
id: ids,
},
success: function(html){
$('#'+id).empty();
$('#'+id).append(html);
NiceSelect.bind(document.getElementById(id), {searchable:true});
},
error: function (xhr, status, error) {
console.log(xhr.responseText || error);
}
});
}
}`
this is the JS in function i called function here
initSelect2('edit-wish-cats', 'wishlists_types', data.wish_cat);