I'm using grease monkey user script to restyle UI and automate initial input on some weird site, which uses jQuery and Select2.
I dealing with row containing two selects:
- organization (options are loaded, empty option is selected, select control is enabled)
- hall (no options, disabled).
I need to make selection in the first one to force second one to load corresponding option and become enabled.
Lets name orgSelect is a HTMLSelectElement with attached events and orgSpan is a "select + span > span.selection > span" element with attached events, created by Select2.
I can set orgSelect.value (obviously).
I can dispatch "change" event for orgSelect and see selected value rendered. But nothing going on with second select.
I can click orgSpan expecting dropdown action (I even seen such a example online and it works), but this doesn't work for me. No drop down on orgSpan.click().
So, I can set value for select2, but how to trigger it properly?
Wellp... somehow I found proper event chain. But I didn't tested it in pure JS. Because, first I decided to try to use jQuery from "unsafe" window and since it working I did the next: