1

I have a button, when simulating a click on this button using jquery/javascript/Ext JS5 in Firefox/Chrome browsers. This button fires it's event, but when doing same thing in IE11, the event does not fire? ANY CLUE?

Here's the way to click the button:

// jquery
$('.buttonId').click(); // works
// javascript 
document.getElementById('buttonId').click(); // works
// ExtJS 5
var ok = Ext.ComponentQuery.query('button[itemId=buttonId]')[0];
ok.fireEvent('click', ok); // works

But doesn't work for IE11

V Kid
  • 117
  • 4
  • 12

3 Answers3

3

I would use:

ok.dispatchEvent("click")

instead of fireEvent, of course you will need to add some logic to detect which browser you are on, so that if IE < v11 then you could continue to use fireEvent().

Please see this from Microsoft about the deprecation of fireEvent and suggested replacement with dispatchEvent():

https://msdn.microsoft.com/en-us/library/ff986080(v=vs.85).aspx

Lingster
  • 977
  • 10
  • 21
  • 1
    If you are not sure, this should be a comment, not an answer. If you are going to tell him he needs more logic, then provide it. You need to provide answers with more explanation. See [How to answer page](http://stackoverflow.com/help/how-to-answer) for help in improving your answer. – Madness Aug 17 '15 at 17:36
  • Hi Madness, thanks for the comment, I've provided link to justify my answer accordingly! – Lingster Aug 17 '15 at 19:52
  • Thanks so much @Lingster! – Madness Aug 17 '15 at 20:00
1

This is a bug. Use this override and it should work!

Example Fiddle: https://fiddle.sencha.com/#fiddle/ls4

Ext.define('EXTJS-13775', {
    override: 'Ext.dom.Element'
}, function(Element) {
    var eventMap = Element.prototype.eventMap;

    eventMap.click = 'click';
    eventMap.mousedown = 'mousedown';
    eventMap.mouseup = 'mouseup';
    eventMap.mousemove = 'mousemove';
    eventMap.dblclick = 'dblclick';
    eventMap.mouseleave = 'mouseleave';
    eventMap.mouseenter = 'mouseenter';
});
Simon Hoss
  • 562
  • 1
  • 3
  • 7
0

This works on all browsers. assume I have a select input named (myDropDown)

if ("createEvent" in document) {
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent("change", false, true);
    myDropDown.dispatchEvent(evt);
}
else
    myDropDown.fireEvent("onchange");

Also, you can refer to fireEvent in IE

Community
  • 1
  • 1
FLICKER
  • 6,439
  • 4
  • 45
  • 75