webfashionist / RichText

WYSIWYG editor developed as jQuery plugin
GNU Affero General Public License v3.0
112 stars 62 forks source link

trigger setContent does not work #101

Closed Feltim closed 1 year ago

Feltim commented 1 year ago
<link href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css" rel="stylesheet" type="text/css">
<script src="https://code.jquery.com/jquery-3.7.0.min.js" integrity="sha256-2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js" integrity="sha256-lSjKY0/srUM9BE3dPm+c4fBo1dky2v27Gdjm2uoZaL0=" crossorigin="anonymous"></script>

<script src="https://kit.fontawesome.com/16fc208f81.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="./plugins/richtext/richtext.min.css">
<script src="./plugins/richtext/jquery.richtext.min.js"></script>

<script language="JavaScript" type="text/JavaScript">
$(document).ready(function(){
    $("#comment").richText();
    $("#comment").trigger("setContent", "test");
});
</script>

<textarea name="comment" id="comment"></textarea>

This is the entire script called test.php and the editor works, jquery works, the setContent does not work

webfashionist commented 1 year ago

Your textarea will be wrapped with nodes specific for the editor. You'd need the following code snippet to make it work:

$('#comment').siblings('.richText-editor').trigger('setContent', 'test');