Add text dynamically CLEditor

I am using CLEditor for the website I am working on. I am trying to add dynamic text to a text box using jQuery. Usually I will use something like:

$('#myText').val('Here some dynamic text');

But that just doesn't work with CLEditor. When disabling CLEditor, it works fine, but turning it on again, the text just disappears. I tried looking at the website for a solution, but I cannot find it. Has anyone had the same problem lately?

Thanks in advance.

+5
source share
6 answers
$("#input").cleditor({width:500, height:250,updateTextArea:function (){....}})
+3
source

CLEditor updates the contents of the iFrame when the textarea blur method is called:

//make CLEditor
$(document).ready(function() {
  $('#text').cleditor();
});

//set value
$('#text').val('new text data').blur();
+24
source

, , - , , ; , - .

// initializing the cleditor on document ready
var $editor = $('#description').cleditor()

, html cleditor, :

// update the text of the textarea
// just some simple html is used for testing purposes so you can see this working
$('#description').val('<strong>testing</strong>');

// update cleditor with the latest html contents
$editor.updateFrame();
+6

, - , .

, , cleditor.

<script type="text/javascript">
$(document).ready(function() {

// Define and load CLEditor
    $("#input").cleditor({
        width: 800,
        height: 300,
        controls: "bold italic underline subscript superscript | color highlight removeformat | alignleft center alignright justify | table | undo redo | cut copy paste pastetext | print source ",
            useCSS: false
    });


// on change dropdown value
    $('#dropdown').change(function() {
// doing AJAX request by GET
        $.get(
// pushing AJAX request to this file
                'ajax/change_dimmensions_table.php',
// pushing some data, from which to determine, what content I need to get back
                    {'dropdown_value':$('#dropdown').val()},
                function(data, textStatus) {
// Clearing the content of CLEditor, adding new content to CLEditor
                        $("#input").cleditor({width:800, height:300, updateTextArea:function (){}})[0].clear().execCommand("inserthtml", data, null, null);
            },
                    'html'
        );
    });
});
</script>

change_dimmensions_table.php:

<?php 
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

if ( ! empty( $_GET['dropdown_value']))
{
    mysql_connect('localhost', 'username', 'password');
    mysql_select_db('database');
    mysql_query("SET names utf8");

    $sql = "
SELECT
    `html_content`
FROM
    `templates`
WHERE
    `dropdown` = '{$_GET['dropdown_value']}'
LIMIT 1
    ";

    $result = mysql_query( $sql) or die( mysql_error() . " SQL: {$sql}");

    if ( mysql_num_rows($result) > 0)
    {
        while ( $row = mysql_fetch_object( $result))
        {
            $html = $row->html_content;
        }
    }

    if ( ! empty( $html))
    {
        echo $html;
    }
}
?>
+2

- , :

$('#myText').cleditor()[0].execCommand('inserthtml','Here some dynamic text');

- , . .

+1

execCommand - , IE, val(). blur()

0

All Articles