Open jeremyblalock opened 3 years ago
Note: I have already published this change here for my personal use: https://www.npmjs.com/package/@inventora/better-dateinput-polyfill
Feel free to test using that version. I am merely contributing this back because it was useful to fix my issue, and I thought others could benefit!
Addresses: https://github.com/chemerisuk/better-dateinput-polyfill/issues/134
Problem
As mentioned in the issue, you currently can't listen for changes on a polyfilled input. This is problematic if you're using React and other frameworks, since the React state & the state of the input will get out of sync.
Solution
I have added a few lines of code to trigger an event that will closely mirror the event that would come from an actual date input in Chrome / Firefox.
document.createEvent
interface, since it has wider support with browsers that are lacking the date input, and it has better compatibility with Reactinput.addEventListener
, and both worked successfully.