4

I am using EasyAdmin Bundle, which seems to use Select2 for internal select form fields. I am trying to capture the onChange event, but I cannot figure out why the following code does not work:

$('#mySelect2Id').on('change', function () {
    console.log($(this).value());
})

Unfortunately, I cannot see anything within the console when I change the value of a Select2. Has someone experienced similar issues? Thanks for your help.

Matteo Cacciola
  • 85
  • 1
  • 1
  • 8
  • is the DOM loaded by the time you are assigning the event? What happens when you log the length of the selector before assigning the event `console.log($('#mySelect2Id').length);` – chiliNUT Jul 15 '21 at 20:22

1 Answers1

0

I have fixed myself. It looks like the problem appears if you import jquery in webpack, together with EasyAdminBundle.

Matteo Cacciola
  • 85
  • 1
  • 1
  • 8