Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE hint text

I'm using Remy Sharp's jQuery plugin to display hints in text boxes.

I'd like to do the same with TinyMCE - display a hint, like "Type some text here.", and when the user focuses the TinyMCE editor, that text should go away. If the editor is empty (no text entered), then on blur the text should be visible again.

Is there a jQuery plugin that is capable of doing this? Or is there an API in TinyMCE that I could use for this functionality?

like image 612
Attila O. Avatar asked Jul 17 '26 18:07

Attila O.


1 Answers

TinyMCE should pass through any content already in the textarea, so

<textarea name="content" id="content">Type some text here</textarea>

should display that text, then with jQuery you should be able to do something like:

TinyMCE.focus(function(){
 if ($(this).getContent() == "Type some text here"){
  tinyMCE.setContent("");
 } else if ($(this).getContent() == ""){
  tinyMCE.setContent("Type some text here");
 }
})

I haven't tested it, but getContent & setContent is what you need from the tinyMCE api... not sure if the .focus() will work right. TinyMCE replaces the textarea with an iframe, so you're not actually typing into the textarea anymore...

like image 175
JKirchartz Avatar answered Jul 19 '26 06:07

JKirchartz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!