user1780456
user1780456

Reputation: 43

jwysiwyg Using the current textarea value as Initial Content

I'm using jwysiwyg on multiple textarea's on one page. However my textarea's have initial pre-filled values which I need it to use. Instead jwysiwyg's default 'Initial content' is used.

my code is:

$(document).ready(function(){
    $('textarea').wysiwyg({
        autoGrow:true, 
        initialContent: this.value,
        controls:"bold,italic,underline,|,undo,redo"
        });
});

Appreciate I could call each textarea individually by id but that seems like lines of code for the sake of it. Think my issue is all down to the way I'm referncing 'this.value' but cant figure it out.

I can solve this by changin the following in jswysywig.js 'initialContent = original.val();' change to 'options.initialContent = original.val();'

Upvotes: 4

Views: 1673

Answers (2)

Jay Brunet
Jay Brunet

Reputation: 3750

In my case, I made a stupid error. value="whatever" is not a textarea attribute. The only reason I'm posting this, I'm guessing other people made the same mistake due to the number of results in Google for this problem. Maybe this was a real bug in jWysiwyg at some point but it's working for me (without any modification) should be working as of v0.97

<textarea id="wysiwyg" rows="10" cols="80" wrap="physical" name="whatever">This is your initial content.</textarea>

Upvotes: 0

Tats_innit
Tats_innit

Reputation: 34117

Is this what you are looking for: http://jsfiddle.net/QjBh4/

Hope this fits your need :))

P.S. - Please feel free to use my demo and create your issue, I will defo try and help you out, if I missed anything!

Script source et. al.

 <link rel="stylesheet" type="text/css" href="http://akzhan.github.com/jwysiwyg/help/lib/blueprint/screen.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="http://akzhan.github.com/jwysiwyg/help/lib/blueprint/print.css" media="print" />
<link rel="stylesheet" href="http://akzhan.github.com/jwysiwyg/jquery.wysiwyg.css" type="text/css"/>
<script type="text/javascript" src="http://akzhan.github.com/jwysiwyg/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="http://akzhan.github.com/jwysiwyg/controls/wysiwyg.image.js"></script>

Sample code

(function($) {
    $(document).ready(function() {
        $('textarea').each(function() {
            value_of_textarea = this.value;
            $(this).wysiwyg({

                autoGrow: true,
                initialContent: function() {
                    return value_of_textarea;
                },
                controls: "bold,italic,underline,|,undo,redo"


            });
        });

    });
})(jQuery);​

Upvotes: 3

Related Questions