﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
12374	Widget dialogs - provide an easy way to access edited widget in onOk / onShow	Wiktor Walc		"While working on a test widget I found it quite hard to get a reference to a widget instance for which a dialog is launched.

Take the code snippet dialog (`dialogs/codesnippet.js`) and add there:

{{{
onOk: function( evt ) {
	console.log(evt);
	console.log(this);
},
onShow: function( evt ) {
	console.log(evt);
	console.log(this);
},
}}}

See that there is no access to a widget object which is created on the fly by the widget system, in case of a new widget. As a result the usage of onOk / onShow as a replacement for commit/setup functions in each UI element is quite troublesome.

There is a workaround for it:

**onShow**

{{{
onShow: function() {
	var widget = editor.widgets.focused;
}
}}}

**onOk**

1. We need to add event handler in an `init` method executed while initializing a widget:

{{{
editor.widgets.add( 'xyz', {
	// ...
	init : function() {
		// ...
		// Pass the reference to this widget to the dialog. See ""onOk"" in the dialog definition, we needed widget there.
		this.on( 'dialog', function( evt ) {
			evt.data.widget = this;
		}, this );
	},
	// ...
}
}}}

2. Then this will work:

{{{
onOk: function() {
	var widget = this.widget;
}
}}}


In ideal world this could be simpler though.


"	New Feature	confirmed	Normal		UI : Widgets	4.3			
