-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
widget startupData object is not being used by widget template #3540
Comments
I have found a solution, but I don't how to make a PR, so I'll put here, so someone could test it, please!
In conclusion, the easy fix is to merge defaults object with commandData.startupData object, with the latter overriding the former, just before outputting the template.. |
I can reproduce the issue using your sample. To simplify it a bit, here are reproduction steps for the issue:
CKEDITOR.plugins.add( 'simplebox', {
requires: 'widget',
init: function( editor ) {
editor.widgets.add( 'simplebox', {
allowedContent: 'div(!simplebox); div(!simplebox-content); h2(!simplebox-title)',
requiredContent: 'div(simplebox)',
editables: {
title: {
selector: '.simplebox-title',
allowedContent: 'br strong em'
},
content: {
selector: '.simplebox-content',
allowedContent: 'p br ul ol li strong em'
}
},
template:
'<div class="simplebox">' +
'<h2 class="simplebox-title">{title}</h2>' +
'<div class="simplebox-content"><p>{content}</p></div>' +
'</div>',
upcast: function( element ) {
return element.name == 'div' && element.hasClass( 'simplebox' );
},
defaults: {
title: 'default title',
content: 'default content'
},
} );
}
} );
CKEDITOR.replace( 'editor', {
extraPlugins: 'simplebox'
} );
editor.execCommand( 'simplebox', {
startupData: {
title: 'updated title',
content: 'updated content'
}
} ); ExpectedWidget should be initialized with updated placeholders i.e ActualWidget is initialized with default values. Overall, there is no strict information in our docs that However, it seems for me more like a feature than a bug as there is no well-written specification for that (at least I couldn't find) and the whole concept is rather based on assumptions than docs. |
Yes, you are right, there is no direct information that startupData is used in the template. It's what I inferred, based on the fact that the template uses default data and startupData overrides it. I think it's very useful to have it and the fix seems (to me at least) rather easy. Then again, I can't speak for the whole internal structure of widget plugin, that's why I believe it's best to leave it for the devs. Temporarily, I'm using my fix and I'm happy with it. |
I realize this ticket is a bit old now, but, is there a solid work-around that doesn't involve the patch? |
Accorrding to the widget docs, I can use:
to create a widget with initial widget data and this data object will overwrite the default data.
However, this doesn't modify the widget template at all.
I have created an example here: http://users.sch.gr/vandr/ckeditor4/
I use unoptimized CKEditor 4.13.0 with simplebox widget.
I have modified the simplebox widget by including "title" and "content" placeholders like so:
and I have registered another copy named simplebox2 widget with defaults object:
The plugin source is here: http://users.sch.gr/vandr/ckeditor4/plugins/simplebox/plugin.js
I created CKEditor like this:
Initially, simplebox2 widget is inserted (which has defaults object), but startupData is wrongly never used in the template and the defaults object is used.
If you press Save to insert simplebox widget (which doesn't have defaults object), startupData is also wrongly not used and I get error:
So, I cannot use execCommand with startupData to create a widget and modify its template. I also found an old question in StackOverflow: https://stackoverflow.com/questions/32149518/ckeditor-widget-receives-data-after-it-has-been-rendered
The text was updated successfully, but these errors were encountered: