Opened 5 years ago

Closed 5 years ago

#12011 closed Bug (invalid)

data returned by getData is not consistent

Reported by: Frederic Steinfels Owned by:
Priority: Normal Milestone:
Component: General Version: 4.0
Keywords: Cc:

Description

I am using inline editing. I am not using getDirty to check for changes, I am comparing the contents delivered by getData (for the sake of consistency with other form fields).

The data that is embedded within a div: <div contenteditable="true" autocomplete="off">...<div>

Whereas ... is: bla<br /><img />

After initializing the editor with CKEDITOR.inline(thisdiv) and reading the content with getData, the content returned is

bla<br><img>

As soon as I click into the editor and do another getData, this content is returned:

bla<br/> <img/>

This causes some problems for me as the content seems to have changed. Please make sure the content is always returned in a consistent manner no matter whether the editor has received focus or not.

Change History (6)

comment:1 Changed 5 years ago by Frederic Steinfels

for some reason, your online editor replaced a newline with a space after pressing the preview button. The correct notation of the last content returned is:

bla<br/> <img/>

comment:2 Changed 5 years ago by Frederic Steinfels

sorry it seems I can not force your tool here to place a newline between <br/> and <img/>

comment:3 Changed 5 years ago by Frederic Steinfels

Summary: date returned by getData is not consistentdata returned by getData is not consistent

comment:4 Changed 5 years ago by Piotrek Koszuliński

Keywords: getData removed
Status: newpending
Version: 4.4.14.0

Interesting problem. Before editor is ready, the content returned from editor.getData() just equals the editable element's innerHTML, because this is our source of data. And the raw HTML is formatted differently than editor formats it later, when its ready. And this cannot be speeded up, because data processor needs all config options and some plugins to be ready.

There's no easy solution for this. My first tip would be to not read getData() before editor is ready (you can check editor.status flag). Other possible solution is not initializing inline editor on element, but on textarea, because it will preserve the data format (http://ckeditor.com/latest/samples/inlinetextarea.html). And the last idea - store the editor's data somewhere in your app (or element's data-* attribute) and preset it (using setData) just after initializing editor, so getData() will return this, rather than raw HTML.

Let us know if these options sounds like solution. I don't think that we can do more, but I'll keep this ticket open for a while, so others can comment it too.

comment:5 Changed 5 years ago by Frederic Steinfels

Thanks. The easiest workaround is indeed the status flag. Changing ckeditor makes no sense.

Side note: The reason I have to check all form fields using javascript is because of autofill and autocomplete not firing the proper change events and I dont want to use the official form submission mechanism which is lame nowadays.

comment:6 Changed 5 years ago by Jakub Ś

Resolution: invalid
Status: pendingclosed

I think we can safely close this ticket because I don't see it as CKEditor bug. @Rainmar is correct and gives you IMO best options to to resolve this issue (getting data after editor is initialized)

One explanation first before I close this ticket. You have mentioned below:

sorry it seems I can not force your tool here to place a newline between

CKEditor formats output HTML in source mode for better user readability. If you check every indentation when comparing HTML then you need to provide it in the same format as CKEditor uses.
You can either adjust your HTML to what CKEditor displays or adjust CKEditor HTML to your HTML with output formation options: http://docs.ckeditor.com/#!/guide/dev_output_format
http://docs.cksource.com/CKEditor_3.x/Howto/FCKeditor_HTML_Output

Note: See TracTickets for help on using tickets.
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy