Search code examples
javascriptwysiwyg

Add content form database to Pells WYSIWYG text editor (Edit function)


Im using Pell's WYSIWYG text editor on my site. https://github.com/jaredreich/pell

Its working fine to create content and save that on the databse, but id like also to edit by import the text from databse into the editor like i do on input with value="$var".

I tried following withouth success:

<div id="editor" value="$VAR" class="pell">$VAR</div>
<div>
  HTML output:
  <textarea class="displayno" value="$VAR" id="html-output"  name="catdesc[]">$VAR</textarea>
</div>

May it will be necessary to import the text inside the init of this script:

var editor = window.pell.init({
element: document.getElementById(\'editor\'),
defaultParagraphSeparator: \'p\',
onChange: function (html) {
    document.getElementById(\'html-output\').value = html
}
})

Can anyone help me out there ?


Solution

  • I was able to do it bymyself:

    Add to init:

    contentDatabase: function () {
        html = document.getElementById(\'html-outpu\').value;
        return html;
    },
    

    Inside the editor script add after intializing "content" and "settings":

      var addContentDatabse = settings.contentDatabase();
      if(addContentDatabse){
        content.innerHTML = addContentDatabse;
      }