I have a widget where I allow users to paste html in the dialog of the widget.
In the data(evt) event method of the widget, I then call evt.sender.parts.content.setHtml(content);.
This works just fine for plain html, however if the html contains elements that should turn into widgets, these do not get initialized.
I have tried calling evt.sender.editor.widgets.checkWidgets();, but that doesn't seem to do anything. In particular no upcast methods are ever called.
I also tried to get the range of the content part, so that I could use editor.insertHtml instead, but cannot find the range anywhere in the dom.Element object.
Then I tried using evt.sender.parts.content.setHtml(evt.sender.editor.dataProcessor.toHtml(content, 'a'));. That calls the upcast method, but for some reason never calls the init method.
Any suggestions how to deal with this?
And I figured it out while typing the question...
You have to call first
evt.sender.parts.content.setHtml(evt.sender.editor.dataProcessor.toHtml(content, 'a'));to process the html and thenevt.sender.editor.widgets.checkWidgets();to process the created html with the uninitialized widgets.To prevent infinite loops with other recursive widgets, the call to
checkWidgets()should be done in asetTimeout. IE: