samclarke / SCEditor

A lightweight HTML and BBCode WYSIWYG editor
http://www.sceditor.com/
Other
643 stars 186 forks source link

When wanting to get the content of editor with val() it returns empty value #953

Open xillibit opened 4 months ago

xillibit commented 4 months ago

When wanting to get the content of editor in live with val() it returns empty value

Steps to reproduce the problem

  1. At start the content of the editor should empty
  2. Write something in the editor
  3. Click on a button which call sceditor.instance(document.getElementById('message')).val();
  4. It return just an empty value
sulaiman0dawod commented 1 month ago

Simple example .

<textarea id="message" name="message" rows="20" cols="70"></textarea>
<script type="text/javascript">
var textarea = document.getElementById('message');
$("#message").sceditor(textarea);
var MyEditor = $("#message").sceditor("instance");
</script>

To view the text in PHP echo $_POST['message'];

to Inserts HTML into WYSIWYG editor OnClick
MyEditor.wysiwygEditorInsertHtml("ddddddddd"); Insert BBcode MyEditor.insertText("ddddddddd");

<a target='dddddd' OnClick="window.parent.PBBEditor.wysiwygEditorInsertHtml(this.target);" />
 Html Link
</a>

Complete example

<textarea id="message" name="message" rows="20" cols="70"></textarea>
<script type="text/javascript">
            var textarea = document.getElementById('message');
            var partialmode = 0;
            sceditor.create(textarea, {
                plugins: 'undo',
                format: 'bbcode',
                bbcodeTrim: false,
                style: "sceditor/minified/themes/content/default.min.css",
                fonts: "Arial,Arial Black,Tahoma,Droid Arabic Kufi,Georgia,Impact,Sans-serif,Serif,Times New Roman,Comic Sans MS,Courier New,Trebuchet MS,Verdana",
                {$_CONF['info_row']['content_dir']}: 'bool',
                width: "100%",
                enablePasteFiltering: true,
                emoticonsEnabled: true,
                emoticonsRoot: "sceditor/emoticons/",
                emoticons:{
                    dropdown: {
                        ':)': 'emoticons/smile.png',
                        ':angel:': 'emoticons/angel.png'
                    },
                    // Emoticons to be included in the more section
                    more: {
                        ':alien:': 'emoticons/alien.png',
                        ':blink:': 'emoticons/blink.png'
                    },
                    // Emoticons that are not shown in the dropdown but will still
                    // be converted. Can be used for things like aliases
                    hidden: {
                        ':aliasforalien:': 'emoticons/alien.png',
                        ':aliasforblink:': 'emoticons/blink.png'
                    }
                },
              emoticonsCompat: true,
                toolbar: "bold,italic,underline,strike|right,center,left,justify|font,size,color,removeformat|cut,copy,pastetext|bulletlist,orderedlist|table|codebrush,quote|horizontalrule,{$mention}image,email,link,unlink|emoticon,youtube,video|bbcodeslist|ltr,rtl|print,maximize,source",

});
$(function() {
    $("#message").sceditor(textarea);
    MyEditor = $("#message").sceditor("instance");

});
</script>