Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#7229 closed bug (notabug)

wrong widget event binding on creation

Reported by: akoptsov Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.widget Version: 1.8.7
Keywords: Cc:
Blocked by: Blocking:

Description

error in handler functions call when using a code like this

<html>
	<head>
	    <link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/themes/base/jquery-ui.css"></style>
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>
		<script type="text/javascript">
			$( function(){
					var elem = $('#elem');

					elem.autocomplete({
						minLength : 0,
						source: ['1', '2', '3', '4', '5'],
						select : function(event, ui) {
						   alert('foo!');
						}
					});

					elem.bind('autocompleteselect', function(event, ui){alert('bar!');});
					
					// on automatic 'autocompleteselect' trigger (using autocomplete from UI)
					// both handlers will fire

					// If we manually trigger selection
					elem.trigger('autocompleteselect', {});
					// the first handler won't fire - however, the second will
				}
			)
		</script>
	</head>
	<body>
		<input type="text" id="elem">
	</body>
</html>

the problem resides in ui.widget's _trigger function which treats both kinds of events separately.

var callback = this.options[ type ];

doesn't consider that 'type' can be not only full name, but also shorthanded.

Solution : if 'type' starts with widget event prefix - should crop event prefix from the beginning of type variable before accessing properties

Change History (7)

comment:2 Changed 9 years ago by Scott González

Resolution: invalid
Status: newclosed

Manually triggering a widget's events isn't supported.

comment:3 in reply to:  2 Changed 9 years ago by akoptsov

Replying to scott.gonzalez:

Manually triggering a widget's events isn't supported.

OK, but if it's technically possible - shouldn't it at least be unambiguous?

comment:4 Changed 9 years ago by Scott González

It is defined, you're triggering an event and all event handlers are executed. The callback that you pass as an option is not an event.

comment:5 Changed 9 years ago by akoptsov

You are most probably right, but I still don't understand one thing:

What's the purpose of passing callbacks as options if not for them to be triggered on events?

Either that, or _trigger function in ui.widjet.js treats these two concepts separately for a reason. And if you know that reason - please tell me :)

comment:6 Changed 9 years ago by Scott González

The callback options are a convenience. Users are never supposed to trigger a widget's events manually because it will likely cause an incorrect state. This is not a discussion that should occur in the bug tracker. If you have actual use cases that you want to discuss, please start a thread on the forums.

comment:7 Changed 9 years ago by akoptsov

Ok, thanks for the directions.

Note: See TracTickets for help on using tickets.