Bug 1387190 - Fire "input" event for <select> and datetime <input>. r=esawin, a=gchang
authorJim Chen <nchen@mozilla.com>
Wed, 16 Aug 2017 11:53:13 -0400
changeset 423814 c23f9c735d299160f9df8d2a5ab0838562f4e013
parent 423813 f592e9f5e8d2a578a8e54e91514ec3e1124150a0
child 423815 72f3e9b7c6ea3cbd5edf816ef3a30c3f5595a219
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin, gchang
bugs1387190
milestone56.0
Bug 1387190 - Fire "input" event for <select> and datetime <input>. r=esawin, a=gchang Fire "input" event in addition to "change" event for both <select> fields and date/time <input> fields. MozReview-Commit-ID: 8UDdF8ZnM2e
mobile/android/chrome/content/InputWidgetHelper.js
mobile/android/chrome/content/SelectHelper.js
--- a/mobile/android/chrome/content/InputWidgetHelper.js
+++ b/mobile/android/chrome/content/InputWidgetHelper.js
@@ -81,22 +81,19 @@ var InputWidgetHelper = {
       return true;
     }
 
     return false;
   },
 
   fireOnChange: function(aElement) {
     let win = aElement.ownerGlobal;
-    let evt = aElement.ownerDocument.createEvent("Events");
-    evt.initEvent("change", true, true, aElement.defaultView, 0,
-                  false, false,
-                  false, false, null);
     win.setTimeout(function() {
-      aElement.dispatchEvent(evt);
+      aElement.dispatchEvent(new win.Event("input", { bubbles: true }));
+      aElement.dispatchEvent(new win.Event("change", { bubbles: true }));
     }, 0);
   },
 
   _isDisabledElement : function(aElement) {
     let currentElement = aElement;
     while (currentElement) {
       if (currentElement.disabled)
         return true;
--- a/mobile/android/chrome/content/SelectHelper.js
+++ b/mobile/android/chrome/content/SelectHelper.js
@@ -137,21 +137,19 @@ var SelectHelper = {
           this.forVisibleOptions(child, aFunction, child);
         }
       }
     }
   },
 
   fireOnChange: function(element) {
     let win = element.ownerGlobal;
-    let event = element.ownerDocument.createEvent("Events");
-    event.initEvent("change", true, true, element.defaultView, 0,
-        false, false, false, false, null);
     win.setTimeout(function() {
-      element.dispatchEvent(event);
+      element.dispatchEvent(new win.Event("input", { bubbles: true }));
+      element.dispatchEvent(new win.Event("change", { bubbles: true }));
     }, 0);
   },
 
   fireOnCommand: function(element) {
     let win = element.ownerGlobal;
     let event = element.ownerDocument.createEvent("XULCommandEvent");
     event.initCommandEvent("command", true, true, element.defaultView, 0,
         false, false, false, false, null, 0);