I need to add a different number of elements to a dialog window each time the dialog window is opened. Here’s my code:
CKEDITOR.on( 'dialogDefinition', function(ev) { var dialogName = ev.data.name; var dialogDefinition = ev.data.definition; if ( dialogName == 'myCustomDialog' ) { dialogDefinition.onShow = function() { var dialogContents = this.definition.getContents('info'); var genericElement = { type : 'text', id : 'generic', label : 'Some Label', }; var editorData = this.getParentEditor().getData(); for (var i = 0; i < someFunction(editorData); i++) { var newElement = genericElement; newElement['id'] += '-' + (i + 1); // "generic-1", "generic-2", etc. dialogContents.add(newElement); }; // console.log(this.definition.getContents('info')); }; } });
It’s not important what someFunction does, just the fact that the number of added dialog elements depends on the editor’s data at the time the dialog window is opened.
The elements are being added to the dialog definition, but the changes are somehow not reflected in the dialog window.
If I put the code of dialogDefinition.onShow = function() {...} outside that function (with minor modifications to the variable definitions), the elements are added, but just the first time the dialog window is loaded.
Any hints?
(I’m cross-posting this at stackoverflow)