Select2 plugin 2 different forms with the same select id

I have an issue with this kind of logic:

$(’#<?php echo $MODULE;?> form#<?php echo $MODULE;?>_form select[name=“People_Id”]’).select2();

the logic is I have different modules that runs in the same time using tab and when I made an update or open the other tab… the select2 is removed. anyone could help me with this

It is not valid to have two elements with the same id value in a single HTML document. You must give each element in the document its own unique ‘id’ value. Note that jQuery will only return (at most) a single match for an ID-based selector.

However, your selector doesn’t need to use IDs. You should be able to use something simpler, like $('select[name="People_ID"]').select2(). This will initialize all of the <select name="People_ID"> elements that currently exist in the DOM. (If you are creating tabs dynamically—or inserting their content dynamically—then the <select> elements you insert will not be initialized unless you call the select2() function after you have inserted the content of the tab.)

I can’t tell from your description exactly what’s going on. Can you post sample code on codepen.io or jsfiddle.net that demonstrates your issue? You don’t need to include your actual data if it is sensitive; but a sample page that shows how you are creating and populating your tabs, and how you are initializing your Select2 widgets, would be very helpful in troubleshooting your problem.