Question Editor API Events
preview:changed
Fires whenever the preview pane is updated, due to authors changing Question or Feature (Widget) attributes.
You would want to be notified about this event firing, because you might want to take some action once the preview is rendered, for example.
The on()
or once()
methods can be used to listen to this event.
Examples
// Run each time the event is fired
authorApp.on('widgetedit:preview:changed', function () {
console.log('This code executes when the preview pane has updated.');
});
// Run only once, the first time the event is fired
authorApp.once('widgetedit:preview:changed', function () {
console.log('This code executes only once, when the preview pane has updated.');
});
Caveats
If the preview pane is not shown, which occurs if viewport width is narrower than the responsive_edit_mode.breakpoint
(800px by default), or global_template
is not set to "edit_preview"
, then this event is still fired for Questions, but not for Features (because some Features float, we don't render them at all if the preview pane is not shown). If you want to be notified when changes are made, it's recommended to use the widgetedit.revisionHistoryState:change
event instead.