1

Reproducing the issue

  1. Select an option in the select2 element.
  2. Navigate to any other page (www.google.com)
  3. Navigate backwards using the browser back button
  4. Notice the option is "selected" but the shown option is not the "selected" option, but instead the option the select2 element is initialized with.

This can be seen on the Basic Usage page from Select2, which is where this gif is sourced from. enter image description here

Attempted Solutions

I know of a "fix" but it requires me to place every select2 call within a window.onpageshow listener.

This solution is heavy handed and doesn't address the actual issue with the placeholder/initialized options replacing the selected option on page load.

Conclusion

I'm looking for a more conclusive answer to this problem, targeting it at the source. Can anyone help me in identifying what css/js to override to remedy this placeholder replacement of the selected option on page load?

Thanks for reading.

Thomas
  • 2,622
  • 1
  • 9
  • 16
  • 1
    Im trying this code in Latest chrome browser but i cant seem to replicate the issue you are facing.... i did the following: save your code as html -> opened and selected a option -> went to google directly by changing url -> clicked back and saw that the option i had selected is still there..... i tried also by removing the script tag of `window.onpageshow` and still i cant find any issues – mrtechtroid Apr 20 '22 at 14:18
  • please let me know if i skipped any step or im missing something from the question – mrtechtroid Apr 20 '22 at 14:19
  • @mrtechtroid Hey, I updated the question with an example directly from the selct2 basic usage page. The gif is sourced from that page. – Thomas Apr 21 '22 at 12:11

0 Answers0