Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple initiating in Modal #80

Open
Shuraih-Usman opened this issue Apr 3, 2024 · 0 comments
Open

multiple initiating in Modal #80

Shuraih-Usman opened this issue Apr 3, 2024 · 0 comments

Comments

@Shuraih-Usman
Copy link

Shuraih-Usman commented Apr 3, 2024

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);

Screenshot 04-03-2024 04 18 31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant