Some Cleditor methods not working

1,274 views
Skip to first unread message

kateray

unread,
Aug 17, 2010, 12:29:17 PM8/17/10
to cleditor
I'm using Cleditor 1.2.2 in a Rails app, to replace the text area of a
form that's initially hidden upon loading. Certain methods that I call
on the cleditor Object seem to be working - $
('#question).cleditor().focus(); for instance, works fine in setting
the cursor into the textarea. $('#question).cleditor().clear() doesn't
do anything, even when I add .refresh() because I'm initializing a
hidden editor.

Actually, what I really want to do is a whole chain of commands like
this:

if ($(this).val() == $(this).data('default') || ''){
$(this).val('');
}

so that the textarea will clear if its value is my default text, but
not if it's something my user has written. But I'd be content to
figure out calling methods on a cleditor object first, and then work
out that.
Thanks to anyone who can help!

-Kate

Chris Landowski

unread,
Aug 17, 2010, 2:48:06 PM8/17/10
to cled...@googlegroups.com
Are you calling refresh before or after making the editor visible?

kateray

unread,
Aug 17, 2010, 2:56:43 PM8/17/10
to cleditor
I'm calling it after the textarea has been made visible. I've tried
calling refresh in the same line as creating the editor, or right
after the editor has been created, doesn't seem to make a difference.

Chris Landowski

unread,
Aug 17, 2010, 3:11:49 PM8/17/10
to cled...@googlegroups.com
The reason I ask is because refresh must be called after the editor is made
visible and not after creation.

After taking a second look at your sample, I believe I have found your
problem. The .cleditor() method returns a jQuery array of cleditor objects
and the methods you are using (focus(), clear(), ect...) are cleditor object
methods.

Instead of this:
$('#question).cleditor().focus();
$('#question).cleditor().clear();

You should be doing this:
$('#question).cleditor()[0].focus();
$('#question).cleditor()[0].clear();

Hope this helps,
Chris

Chris Landowski

unread,
Aug 17, 2010, 3:28:23 PM8/17/10
to cleditor
Better yet, try something like this:

$('#question).cleditor()[0].focus().clear();

Remember, most cleditor methods support chaining!
Message has been deleted

Chris Landowski

unread,
Aug 17, 2010, 4:26:40 PM8/17/10
to cled...@googlegroups.com
I assume that my last post resolved your initial problem with clear?

To disable an editor, try something similar to this:
$('#question').cleditor()[0].disable(true);

To hide an editor, try something similar to this:
$('#question').cleditor()[0].$main.hide();

For clarity in code, I would typically cache the editor object into a
variable first, like this:
var editor = $("#question").cleditor()[0];
editor.$main.hide();
// do some initialization...
editor.$main.show();
editor.refresh().focus();

Hope this helps,
Chris

-----Original Message-----
From: cled...@googlegroups.com [mailto:cled...@googlegroups.com] On Behalf

Of Andre H.
Sent: Tuesday, August 17, 2010 3:04 PM
To: cleditor

Subject: Re: Some Cleditor methods not working

@Chris:
How can I hide/ disable cleditor? Could you post me an example? I tried it
with disable() but doesn't work (I think I use it the wrong way...).

kateray

unread,
Aug 17, 2010, 4:27:17 PM8/17/10
to cleditor
Thanks, that worked for clearing the form! Only other small issue is
that I also wanted to hide some other elements on the page upon the
editor focus event. They're not popups, so .hidePopups() doesn't work,
and $('#question).cleditor()[0].focus(function(){ $('#list').hide() })
doesn't either.
Thanks again, I'm quite new to jQuery still.
Kate

Chris Landowski

unread,
Aug 17, 2010, 4:35:24 PM8/17/10
to cled...@googlegroups.com
The cleditor.focus() method is a method and not an event or callback so that
definitely would not work.

What you could do is hook into the iframe focus event like so:


var editor = $('#question').cleditor()[0];

editor.$frame.focus(function() {
// do something here...
});

This should work cross browser!

Hope this helps,
Chris

-----Original Message-----
From: cled...@googlegroups.com [mailto:cled...@googlegroups.com] On Behalf
Of kateray

Sent: Tuesday, August 17, 2010 3:27 PM
To: cleditor

kateray

unread,
Aug 18, 2010, 3:21:54 PM8/18/10
to cleditor
Hm, doesn't seem to work. Tried using editor.$frame.focus as well,
that doesn't do anything either..
Kate

Chris Landowski

unread,
Aug 18, 2010, 3:54:48 PM8/18/10
to cled...@googlegroups.com
I use this same logic in CLEditor, so I'm sure it works. I would start
debugging the code using console.log and firebug to confirm that the focus
event of the iframe is firing.

Tamás Dezsö

unread,
Jan 15, 2013, 3:40:45 AM1/15/13
to cled...@googlegroups.com
I know it's been a while, but I am facing this problem now...

Chris: using editor.$frame.focus(handler) does not work for me either.

The only thing that I found to work is:
$(editor.doc.body).focus(handler);
BUT only in IE and it would even fail here sometimes.

If anyone came up with a workaround in the meantime, I would really appreciate it.

Thanks,
Tamas

Toby

unread,
Jan 15, 2013, 12:23:12 PM1/15/13
to cled...@googlegroups.com
Sorry, google groups doesn't have me as joining
this group, but I continue to get the emails.

Thanks,

Tobiah

Tamás Dezsö

unread,
Jan 15, 2013, 3:52:04 PM1/15/13
to cled...@googlegroups.com

Toby, please see support.google.com/groups/answer/46608/?hl=en

Best,
Tamás

Reply all
Reply to author
Forward
0 new messages