Welcome Guest Search | Active Topics | Sign In | Register

Enhancement to the Escape key in eo:Dialog Options
Mark Rae
Posted: Saturday, November 15, 2008 4:13:57 AM
Rank: Advanced Member
Groups: Member

Joined: 11/13/2008
Posts: 43
Hi,

I understand from a previous thread that it's not possible to prevent the Escape key from closing an eo:Dialog. I'm really puzzled by this...

I tend to use dialogs in web apps to allow users e.g. to add new records etc, and it's really irritating if someone is half-way through making some data changes and hit the Escape key by accident.

You've obviously added the Escape key functionality, so how hard would it be to wrap this in a boolean?

Also, the Close [X] button in the top-right corner of an eo:Dialog seems to be set to fire on the MouseDown event rather than the MouseClick or MouseUp event. This is completely non-standard behaviour. Can it be changed so that it traps the MouseClick or, even better, MouseUp event instead?

Thanks

Mark
eo_support
Posted: Saturday, November 15, 2008 6:59:57 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

We looked into the ESC key issue further and realized that actually our developer has already put that in. :) You would need to handle the dialog's ClientSideOnCancel event to do that. It will be something like this:

Code: JavaScript
function cancel_handler()
{
    return confirm("Are you sure?");
}


Code: HTML/ASPX
<eo:Dialog ClientSideOnCancel="cancel_handler" ....>
....
</eo:Dialog>


We will look into the close button issue and see if we can change that. Thanks for your suggestion!
Mark Rae
Posted: Saturday, November 15, 2008 7:16:39 AM
Rank: Advanced Member
Groups: Member

Joined: 11/13/2008
Posts: 43
eo_support wrote:
You would need to handle the dialog's ClientSideOnCancel event to do that.

Thanks for that.

I was hoping that I could simply put return false; in the cancel_handler() event, but this actually prevents the Dialog from being closed by clicking the Close button.

Do you have a method for differentiating between pressing the Escape key and clicking the Close button...?
eo_support
Posted: Saturday, November 15, 2008 7:34:51 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

No. I do not believe there is an easy way to do that now. Currently clicking close button works the same way as ESC key because both means "canceling the dialog" and most users don't care about distinguishing the two. We will see if we can pass you the event object in a future release (you can use window.event for now, but that's for IE only) so that you can examine the event object by yourself and determine whether it's an ESC event or something else.

Thanks
Mark Rae
Posted: Saturday, November 15, 2008 7:48:40 AM
Rank: Advanced Member
Groups: Member

Joined: 11/13/2008
Posts: 43
eo_support wrote:
No. I do not believe there is an easy way to do that now. Currently clicking close button works the same way as ESC key because both means "canceling the dialog" and most users don't care about distinguishing the two. We will see if we can pass you the event object in a future release (you can use window.event for now, but that's for IE only) so that you can examine the event object by yourself and determine whether it's an ESC event or something else.


OK, thanks.
Mark Rae
Posted: Saturday, November 15, 2008 8:22:03 AM
Rank: Advanced Member
Groups: Member

Joined: 11/13/2008
Posts: 43
eo_support wrote:
you can use window.event for now, but that's for IE only

Here's a cross-browser compatible solution for preventing the Escape key from closing the Dialog:

Code: JavaScript
var intKeyCode;
function handleKeyPress(evt)
{
    intKeyCode = (window.event) ? event.keyCode : evt.which;
    return intKeyCode;
}
document.onkeydown = handleKeyPress;
		
function cancel_handler()
{
    if (intKeyCode == 27) { return false; }
}


eo_support
Posted: Saturday, November 15, 2008 9:10:44 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
This is awesome! Thanks for sharing!
Mark Rae
Posted: Saturday, November 15, 2008 9:29:12 AM
Rank: Advanced Member
Groups: Member

Joined: 11/13/2008
Posts: 43
eo_support wrote:
This is awesome! Thanks for sharing!

Needs a small tweak, as follows:

Code: JavaScript
var intKeyCode;
function handleKeyPress(evt)
{
    intKeyCode = (window.event) ? event.keyCode : evt.which;
    return intKeyCode;
}
document.onkeydown = handleKeyPress;
		
function cancel_handler()
{
    if (intKeyCode == 27) 
    {
        intKeyCode = 0;
        return false; 
    }
}


Something else you might want to consider is giving the eo:Dialog a 'dirty' property which could be inspected in the client-side events. This would allow developers to inform users that the Dialog contains unsaved edits. Incidentally, this isn't particularly difficult to code manually, but it does involve adding a page-level JavaScript variable to the <script> tag for each Dialog, plus JavaScript handlers to every editable control within the Dialog...
eo_support
Posted: Saturday, November 15, 2008 9:56:59 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

As for the dirty flag, we have already considered that and decided against it because every user can have different scenarios. For instance, user can have "completed changes" and "incompleted changes", and they may want "completed changes" to be regarded as dirty and "incompleted changes" to be discarded. Also, not all "changes" can be detected/verified in a unified way. Consider user uses our TabStrip control and changed the active tabs. You won't know that unless you call our client side JavaScript interface. For those reasons we’d prefer to leave that part to the end user.

Thanks
Mark Rae
Posted: Sunday, November 16, 2008 9:22:17 AM
Rank: Advanced Member
Groups: Member

Joined: 11/13/2008
Posts: 43
Back to the Escape key, is is possible to include arguments in the ClientSideOnCancel method? e.g.

Code: HTML/ASPX
ClientSideOnCancel="cancel_handler('Are you sure you want to cancel?')"

Code: JavaScript
function cancel_handler(pstrConfirm)
{
    if (intKeyCode == 27) 
    {
        intKeyCode = 0;
        return confirm(pstrConfirm); 
    }
}
eo_support
Posted: Monday, November 17, 2008 6:21:49 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

Unfortunately that is not possible. All arguments are provided by our controls, just like your server side Page_Load handler is always called by the page with two pre-defined arguments. You can take a look of this topic to get more details on that:

http://www.essentialobjects.com/ViewDoc.aspx?t=clientapi_howto.html

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.