Page 1 of 2
Onrowclick Browser Compatibility
Posted: Thu Jan 16, 2014 1:41 pm
by DaveLClarkI
I have the following code being executed in a grid onrowclick event but I'm finding that it is only working in IE. I think it used to work in Firefox but has stopped working. Know why?
Code: Select all
window.setTimeout(function()
{
wob.countGridRowSelections("ACLKUPGS", "*IN30");
}, 100);
Note that I have to execute the function after the event completes so that I get the correct count of the number of rows currently selected. When that count is greater than one, a message pops up in the page to keep the user informed of multiple selections. The message pops up in IE but does not pop up in Firefox.
So, I set a Firebug breakpoint on the first line of code in the function to see if there is some error occurring. However, it never stops at the breakpoint. Thus it looks like the function is never being executed. Know why?
Re: Onrowclick Browser Compatibility
Posted: Thu Jan 16, 2014 4:28 pm
by Scott Klement
I just wrote a quick test, and my 'onrowclick' fired in Firefox without problems, I also had it do a setTimeout(), this also fired.
Can you tell me how to reproduce the problem you're seeing?
Re: Onrowclick Browser Compatibility
Posted: Thu Jan 16, 2014 4:51 pm
by DaveLClarkI
The following is the exact code I have in the onrowclick event. All of it works fine in IE and only the "else" half works in Firefox. I started up Firebug and set a breakpoint on the first line of code in the countGridRowSelections() function and the breakpoint is never hit. Thus, I have no idea where to go from here.
Code: Select all
if (get("outMaint") != 'hidden')
{
window.setTimeout(function()
{
wob.countGridRowSelections("ACLKUPGS", "*IN30", event);
}, 100);
}
else
{
changeElementValue("txtOption", "Select");
pui.click("lnkSelect." + row);
}
Re: Onrowclick Browser Compatibility
Posted: Thu Jan 16, 2014 6:08 pm
by Scott Klement
Well, if it's doing the 'else' it must be running this code, right? So you're thinking that the setTimeout() code is not firing, I guess? Can you try making the code look like this?
Code: Select all
window.setTimeout(function()
{
alert("hello from setTimeout");
wob.countGridRowSelections("ACLKUPGS", "*IN30", event);
}, 100);
I don't 100% trust firebug... I've had too many times when it didn't do what I was expecting :-) So, I would stick that alert() in there and see if the setTimeout is firing or not. If it's not firing, then I would see if the code that starts the timeout is firing (with another alert). If that's working, I'd check the return value from setTimeout and see if maybe it's returning an error or something. I believe the event code like onrowclick is called from within a try/catch group. Often if there's an error in the code somewhere, the code will appear to "just stop" at some point, and that's because it's stopping with an error, and the try/catch is catching it, so the error doesn't end up in the console.
Re: Onrowclick Browser Compatibility
Posted: Thu Jan 16, 2014 6:08 pm
by David
The 'setTimeout' call is coded correctly. My first thought would be that the if condition is false for some reason...
Don't know why that should be, but seems like the logical explanation, just looking at this one code snippet.
Re: Onrowclick Browser Compatibility
Posted: Thu Jan 16, 2014 6:13 pm
by DaveLClarkI
Scott Klement wrote:I don't 100% trust firebug... I've had too many times when it didn't do what I was expecting :-) So, I would stick that alert() in there and see if the setTimeout is firing or not.
I'll give that a go and post back my results. Thanks.
Re: Onrowclick Browser Compatibility
Posted: Thu Jan 16, 2014 6:30 pm
by DaveLClarkI
OK, found the problem. I went the whole nine yards and coded it as follows. The result is that the third alert() fired. Then, I realized that just because Profound UI passes in an "event" object does not mean that the asynchronous execution of my function (when the timer fires) is going to have access to that object. That is why it works in IE -- because IE has a global "event" object while Firefox does not. Thanks.
Code: Select all
if (get("outMaint") != 'hidden')
{
alert("creating timer");
window.setTimeout(function()
{
alert("timer fired");
try
{
wob.countGridRowSelections("ACLKUPGS", "*IN30", event);
}
catch(e)
{
alert("call to function failed");
}
}, 100);
}
else
{
changeElementValue("txtOption", "Select");
pui.click("lnkSelect." + row);
}
Re: Onrowclick Browser Compatibility
Posted: Thu Jan 16, 2014 7:01 pm
by DaveLClarkI
This is more a JavaScript question than a Profound question but, is there a way to pass the event object to a function executing from a timer? I think that may be part of the reason why IE uses a global event object. But, I was reading and saw a comment about passing the event object to an asynchronous function via a little known format for the parameter list to the setTimeout() function. I just tried it, though, and it didn't seem to work -- perhaps an outdated comment. So, any ideas? Thanks.
Re: Onrowclick Browser Compatibility
Posted: Thu Jan 16, 2014 7:09 pm
by David
This is a bug, actually an omission on our part.
We recently put in this feature to set the 'event' variable within the scope of all widget events. It looks like this was missed for the grid. So 'event' is simply not defined in the grid event handlers. It is on other widgets.
So what happens then is that your code is picking up on IE's 'window.event', where we haven't defined anything.
That your function is running asynchronously is not the problem. The 'event' variable (if we had defined it properly) would simply copied into the scope of the function you're passing to 'setTimeout', due to the concept of 'closures' in JavaScript:
https://developer.mozilla.org/en-US/doc ... e/Closures
So, your code is perfectly fine and would/should work, assuming we set 'event' properly in the grid event handlers. We'll fix that up.
Meanwhile, unfort., I don't think you have any way to grab it in FireFox, due to it not having a global event property like IE. This is why we implemented this feature to begin with, but apparently not 100% complete.
Sorry for the confusion.
Re: Onrowclick Browser Compatibility
Posted: Thu Jan 16, 2014 7:17 pm
by DaveLClarkI
Yep, based on my past experience, I was pretty sure that my original code should have worked. Didn't get a hint, though, that the actual problem was that the event object was not being passed to this grid event. I had seen the note about adding event object support to all Profound events. ;-)