Opened 10 years ago
Closed 10 years ago
#12855 closed Bug (duplicate)
Secondary value set doesn't work as expected in standard mode
Reported by: | Alexey | Owned by: | |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | General | Version: | |
Keywords: | Cc: |
Description
I just need to set a value 1, then a value 2, without a delay. However CKEditor state and behaviour is invalid.
http://ckeditor.com/demo See "Standard editor" demo.
Open JS-console then type right in your browser (I use the latest Chrome 39.0.2171.99 (64-bit) / OS X):
CKEDITOR.instances.editor1.setData('1234'); CKEDITOR.instances.editor1.setData('4567'); console.log(CKEDITOR.instances.editor1.getData())
Now, press "Source" button in the toolbar, then repeat the logging-test:
console.log(CKEDITOR.instances.editor1.getData())
Change History (6)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
I know about async nature of setData… However, my code has separated parts, like
- create CKEditor instance
- clear value to the default state (that calls setData)
- set required value via setData … (optional)
I can't skip step 2, because I dunno anything about next step 3.
Actually I have model that simple loading and deserialising data. But before it clears all controlled widgets to their default states.
comment:3 Changed 10 years ago by
If there is no way to use setData many times without conflicts, that it looks like someone sits inside WC, you know it, and you need to access the same WC, but can't… The solution is new WC, so you're going there. By other words, in case of CKEditor – I need to create a new instance… for every setData call, just to protect from previous async-call.
My solution in cases like that is TSN. I already used it. The code is:
setVal: (val, tsn) -> return if tsn? && @data.tsn != tsn @data.cachedVal = '' + (@preSetVal(val) || '<p></p>') @data.tsn++ editor = @currentEditor() if editor && editor.status == 'ready' editor.setData(@data.cachedVal) else tsn = @data.tsn @initDOM () => @setVal val, tsn
But it won't work for CKEditor without modifying it.
comment:4 Changed 10 years ago by
Status: | new → pending |
---|---|
Version: | 4.4.6 |
If there is no way to use setData many times without conflicts
What about below code (there is a callback in setData, executed after it has finished)
var editor = CKEDITOR.replace( 'editor1', {}); editor.setData( '', function() { editor.setData( 'bar' ); } ); });
IMHO it does just what you need. Please see http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-setData.
comment:5 Changed 10 years ago by
Yep, I understand callback solution. But the problem is – I don't know anytime is next setData call dirty or not. I currently solved the problem via the flag that means any setData() in progress or not. I set the flag before calling setData, and clear it inside the callback. For setData I have the wrapper that does waiting and delayed call if previous setData is still in the progress state, it also uses TSN to prevent race condition.
comment:6 Changed 10 years ago by
Resolution: | → duplicate |
---|---|
Status: | pending → closed |
@UncleMiF Thank you for the input, this issue however is a duplicate of more genral one #11502
Inline mode works as expected. The problem only when CKEditor created in standard mode.