jQuery: The Write Less, Do More JavaScript Library

Ticket #1993 (closed bug: fixed)

Opened 5 months ago

Last modified 5 months ago

trigger doesn't return value when function is passed with extra parameter

Reported by: pwoldberg Assigned to: davidserduke
Type: bug Priority: critical
Milestone: 1.2.2 Component: event
Version: 1.2.1 Keywords: event trigger
Cc: Needs: Review

Description

In ui.draggable.js the following code is used:

var nv = $(this.element).triggerHandler("drag", [e, that.prepareCallbackObj(this)], o.drag);

a value to nv is only returned when using .bind('drag', function) on the draggable element, if you use the drag from the options it will not return the value.

The problem is in the event component:

174	            if ( extra && extra.apply( element, data ) === false )
175	                val = false;

it will only return false but no other values.

Attachments

Change History

Changed 5 months ago by davidserduke

  • need changed from Review to Test Case
  • owner set to davidserduke
  • status changed from new to assigned

I'm not sure I follow the problem. If you look at the jQuery.trigger function (that you clipped that section above out of) you'll see it sets the val variable in several places including

if ( jQuery.isFunction( jQuery.data(element, "handle") ) )
  val = jQuery.data(element, "handle").apply(element, data");

so trigger could return other values in theory. But as event handlers usually return either nothing (undefined) or false, this typically isn't an issue.

What do you expect to be returned? I'm not familiar with the drag code so any other test case you have showing the problem would be useful.

Changed 5 months ago by pwoldberg

It gives back a value if bind is used. The problem is when bind is not used but the function is passed using the extra parameter of the trigger function.

The ui.draggable uses the triggerHandler function to trigger the event and passes the o.drag, which is the drag function set in the options. I want to use the return to restrict the position of the draggable element.

It could also be that it is used wrong in the draggable plugin.

Changed 5 months ago by davidserduke

Ahh, ok I understand what you are saying now. I didn't think that was how the extra function was supposed to work (and it isn't programmed that way) but maybe it should be. And clearly ui.draggable is trying to. I'll do a bit more research and see what I can find out.

Changed 5 months ago by davidserduke

  • need changed from Test Case to Review
  • status changed from assigned to closed
  • resolution set to fixed

Fixed in [4001]. Although more of a design change than a bug fix, the extra function now will overwrite the return value unless undefined is returned either explicitly by the function or by the lack of any other return value.

Note: See TracTickets for help on using tickets.