Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appending text to text area using WYSIHTML5 and jQuery

I'm using the latest (0.3.0) version of WSYIHTML5 for a message board. One of the features of the board is a quote post option. I've been trying to figure out how to append the quote to the text area.

I have the following jQuery as a test

$('.quote').click(function(){
  $('textarea').append('test this');
  alert($('textarea').text());
});

The alert shows the text has appended to the hidden textarea, but it does not update in the iframe of the WYSIHTML5 view.

What's weird is if I straight up append the text after initializing the WYSIHTML5, it appends just fine.

Any ideas on getting this to work?

like image 836
Viet Avatar asked Nov 19 '25 07:11

Viet


1 Answers

So in order to update the iframe and have it format any text with HTML, I did the following..

var value = editor.getValue();
var text = '<b>some text</b>;'
editor.setValue(value + text, true);

This is assuming WYSIHTML5 is instantiated under the variable 'editor'. It'll append the quote, plus format the text correctly. The boolean value is if you want the value to be run through the WYSIHTML5 parser rules.

If anyone knows a better way of doing it, I'm all ears.

like image 182
Viet Avatar answered Nov 20 '25 22:11

Viet



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!