How to conditionally close a jQuery Overlay?
I am providing a custom close button for a jQuery Overlay.
When this button is clicked, I want to validate a form inside the Overlay, and close th开发者_JS百科e Overlay if and only if the form is valid.Example (doesn't work... always close no matter what)
$('.trigger[rel]').overlay(
{
close: '.ovclosebutton',
onClose: function()
{
if( validateSomething() )
this.getOverlay().close();
else
displayErrorInOverlayButDontCloseIt();
}
});
How can I acheive this ?
It appears you are using jQuery tools overlay. Looking at the event methods you probably need to tie into onBeforeClose
instead of onClose
onBeforeClose
before the overlay is closed
onClose
when the overlay is closed
Not sure if this will work with the plugin but might be a start for some pseudo code.
$('.trigger[rel]').overlay(
{
close: '.ovclosebutton',
onBeforeClose: function()
{
if( validateSomething() )
return true; //let the overlay close by default.
else{
displayErrorInOverlayButDontCloseIt();
return false; //block the close
}
}
});
Looking at the event refrence you should be able to cancel the close using onBeforeClose
Before and after events These tools provide both the onBefore event which occurs before some action is taken and the on event that occurs at the time (or after) an action takes place. You can have custom functionality bound to these events. All tools provide such events and they share a common naming policy. The onBefore event provides you with the possibility of cancelling the action.
all you need to know about this can be found here
http://www.erichynds.com/jquery/using-deferreds-in-jquery/#
精彩评论