I am facing a challenge where I need to dynamically add varying numbers of elements to a dialog window each time it is opened. Below is the code I am working with:
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'));
};
}
});
The issue I'm facing is that although the elements are added to the dialog definition, they are not reflected in the dialog window itself.
If I move the code of
dialogDefinition.onShow = function() {...}
outside of that function (with slight adjustments to variable definitions), the elements get added, but only the first time the dialog window loads.
Any suggestions or hints on how to resolve this?