Skip to content

Commit

Permalink
Supports input and change DOM events
Browse files Browse the repository at this point in the history
  • Loading branch information
brianblakely committed Mar 9, 2016
1 parent dddace6 commit f9a9a53
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions nodep-date-input-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,25 @@ class Picker {
this.input.focus();
this.hide();

// Make AngularJS see the change.
const fakeEvent = document.createEvent(`KeyboardEvent`);
fakeEvent.initEvent(`change`, true, false);
this.input.dispatchEvent(fakeEvent);
// Dispatch DOM events to the input.
let inputEvent;
let changeEvent;

// Modern event creation.
try {
inputEvent = new Event('input');
changeEvent = new Event('change');
}
// Old-fashioned way.
catch(e) {
inputEvent = document.createEvent('KeyboardEvent');
inputEvent.initEvent('input', true, false);
changeEvent = document.createEvent('KeyboardEvent');
changeEvent.initEvent('change', true, false);
}

this.input.dispatchEvent(inputEvent);
this.input.dispatchEvent(changeEvent);
}

refreshDaysMatrix() {
Expand Down

0 comments on commit f9a9a53

Please sign in to comment.