chemerisuk / better-dateinput-polyfill

input[type=date] polyfill
http://chemerisuk.github.io/better-dateinput-polyfill/
MIT License
259 stars 58 forks source link

Adds eventlistener support via document.createEvent #135

Open jeremyblalock opened 3 years ago

jeremyblalock commented 3 years ago

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.

jeremyblalock commented 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!