Opened 10 years ago

Last modified 10 years ago

#12374 confirmed New Feature

Widget dialogs - provide an easy way to access edited widget in onOk / onShow — at Version 1

Reported by: Wiktor Walc Owned by:
Priority: Normal Milestone:
Component: UI : Widgets Version: 4.3
Keywords: Cc:

Description (last modified by 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 );
	},
	// ...
}
  1. Then this will work:
onOk: function( evt ) {
	var widget = this.widget;
}

In ideal world this could be simpler though.

Change History (1)

comment:1 Changed 10 years ago by Wiktor Walc

Description: modified (diff)
Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy