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 2
Reported by: | Wiktor Walc | Owned by: | |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | UI : Widgets | Version: | 4.3 |
Keywords: | Cc: |
Description (last modified by )
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
- 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 ); }, // ... }
- Then this will work:
onOk: function() { var widget = this.widget; }
In ideal world this could be simpler though.
Change History (2)
comment:1 Changed 10 years ago by
Description: | modified (diff) |
---|
comment:2 Changed 10 years ago by
Description: | modified (diff) |
---|