sferik/rails_admin — Issue #869: Problem with ckeditor
Author: kot-begemot
Created: 2011-11-30 15:25:42+00:00
State: open

Hello Guys. Thanks for cool Panel =)

Recently(today), a ckeditor integration stop working.
It was working day ago, so it is hardly to believe that the problem lies somewhere in config, However there is a config for the problematic model:

```
config.model Article do
edit do
include_all_fields
field :content do
ckeditor { true }
end
end
end
```

It failing with following error:

Uncaught [CKEDITOR.editor.replace] The element with id or name "#article_content_field textarea" was not found.

Here is its backtrace:

a.editor.replaceckeditor.js:7
dckeditor.js:8
a.replaceckeditor.js:8
(anonymous function)edit:138
jQuery.Callbacks.firejquery.js:1047
jQuery.Callbacks.self.fireWithjquery.js:1165
jQuery.extend.readyjquery.js:436
DOMContentLoaded

Looking into the problem we found out that the JavaScript code generated after text field that should replace it with ckeditor is as follows:

```
jQuery(function($) {
if(!$("#article_content_field").parents(".fields_blueprint").length) {
if(!$("#modal").length) {
CKEDITOR.replace('#article_content_field textarea', { customConfig : '/javascripts/ckeditor/config.js' });
}
}
});
```

a.editor.replace function in ckeditor.js looks as follows:

```
a.editor.replace = function (b, c)
{
var d = b;
if (typeof d != 'object')
{
d = document.getElementById(b);
...
if (!d) {
throw '[CKEDITOR.editor.replace] The element with id or name "' + b + '" was not found.';
}
}
d.style.visibility = 'hidden';
return new a.editor(c, d, 1);
};
```

executing following code in JacaScipt console Give an null

document.getElementById('#article_content_field textarea');

But this one replaces textarea with Ckeditor:

CKEDITOR.replace('article_content', { customConfig : '/javascripts/ckeditor/config.js' });

Is this a bug or we missing something?