0

I am trying to use the following command to insert a text to the CKEditor:

CKEDITOR.instances.Body.insertText('$${FIRSTNAME}');

The above command works fine when the cursor is at plain text. When i try to insert the text between a text which has attribute, it inserts on single $ instead of $$ of $${FIRSTNAME}. I have uploaded the sample to the jsbin to reproduce the issue

http://jsbin.com/ahikeh/1

Please suggest an alternative to fix this issue.

2 Answers 2

2

This is an ugly bug :D I debugged the code and find the reason:

https://github.com/ckeditor/ckeditor-dev/blob/master/core/editable.js#L1616

String#replace method treats $$ as one $ (https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/String/replace), so the data should have been protected.

I'm afraid that there's no simple workaround right now since you cannot escape the data beforehand. Depending on context the replace method will or won't be used.

So the best option will be to use other template pattern - e.g. %%{foo} - it will work correctly. And when getting data from the editor you can replace %% with $$.

Ticket: http://dev.ckeditor.com/ticket/10367

1
  • Thanks for the update. We'll try to use a different symbol rather than $, until this issue gets fixed.
    – Prasad
    Apr 23, 2013 at 8:42
1

Try using insertHtml() instead:

CKEDITOR.instances.Body.insertHtml('<b>$${FIRSTNAME}</b>');

Updated Demo

2
  • Its working fine with insertHtml, but i have an another concern. I need to insert that value based on the text in the CKEditor, If I insert it between a strong tag, it should look like bold and if I insert it in plain text, it should look like that. The inserted text should have the similar style of the text where the cursor is currently located.
    – Prasad
    Apr 23, 2013 at 6:12
  • if the cursur is within a span with a style or a bold tag.. The inserted html would be the same style.. The only reason it could break is because of block level elements within inline elements. Which is not correct within html.
    – Spons
    Apr 23, 2013 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.