Opened 7 years ago

Closed 7 years ago

#8579 closed bug (duplicate)

_normalizeArguments not working properly when ({effect: "someeffect"}, callback)

Reported by: sparkybg Owned by:
Priority: minor Milestone: 1.10.0
Component: ui.effects.core Version: 1.9.0-rc.1
Keywords: Cc:
Blocked by: Blocking:

Description

Summary:

If "hide" effect for a dialog is defined, "close" event is not invoked when dialog closes.

How to reproduce:

Here is it on jsbin: http://jsbin.com/ocesik/1/edit

$("<div></div>).dialog({
   modal: true,
   autoOpen: true,
   hide: {effect: "fade", duration: 150}, //if hide effect is defined, "close" event is not triggered
   close: function () {alert("dialog:close")}
});

Possible cause:

This results in calling of:

_normalizeArgumets({effect: "fade", duration: 150}, function () {alert("dialog:close")});

but the callback is lost after the first "if" in the _normalizeArguments function:

// here "options" parameter is "function () {alert("dialog:close")}"
if ( $.isPlainObject( effect ) ) {
   options = effect; //here the callback is lost!!!
   effect = effect.effect;
}
// here "options" is the same as "effect" parameter: "{effect: "fade", duration: 150"}, so, the callback is lost and not invoked

Possible fix:

First "if" in the function should be replaced by:

if ( $.isPlainObject( effect ) ) {
   callback = options; //the callback is not lost anymore
   options = effect;
   effect = effect.effect;
}

Change History (5)

comment:1 Changed 7 years ago by Scott González

Milestone: 1.9.01.10.0

comment:2 Changed 7 years ago by acouch

Owner: set to acouch
Status: newassigned

comment:3 Changed 7 years ago by acouch

Indeed, the issue comes about at line 250 (at 4d5197) of jquery.ui.dialog, which makes a call to an undocumented version of .hide().

We could put an explicit check there for an object, but it does seem like a reasonable method signature.

this.uiDialog.hide( this.options.hide, function() {
        that._trigger( "close", event );
});

comment:4 Changed 7 years ago by acouch

Owner: acouch deleted
Status: assignedopen

I've developed two possible fixes, neither of them particularly clean.

As you suggested, we could update the effects show/hide methods to allow these parameters. However, this behavior is currently unspecified, so it that solution may have wider ramifications. Also, it introduces an interesting synchronization question. If both callbacks are provided, which should be executed first?

https://github.com/couchand/jquery-ui/commit/161b2bc7089a47210a0c94de381fea29fec6e709

We could also explicitly check for the object in the dialog's close method. This way we can explicitly choose, in context, which handler to call first. In my opinion, the complete callback in the hide options should be called before firing the close event.

https://github.com/couchand/jquery-ui/commit/e0345032438696bc70ee0ff3344f6e298882d529

comment:5 Changed 7 years ago by Scott González

Resolution: duplicate
Status: openclosed

Duplicate of #8684.
Also see #8670

Note: See TracTickets for help on using tickets.