Kademi / keditor

KEditor is a jQuery plugin which provides a content editor with drag n drop, configurable contents
http://kademi.github.io/keditor/
MIT License
319 stars 153 forks source link

I can't set content on the editor. Tried different selectors but can't set content on editor [BUG] #207

Closed nivanmorgan closed 5 years ago

nivanmorgan commented 5 years ago

Describe the bug A clear and concise description of what the bug is. I can't set content on the editor. I am using the latest version. I downloaded my assets from github. I am trying to add an html button to allow users to paste or edit the html. But found problems setting the content back in the editor. So I tried removing all code and just setting the initial content with no use.

Version

latest verson

To Reproduce

Here is how I initialized my editor

$('#contentarea').keditor({
        title: '',
        snippetsUrl: '{{ CDN::asset("/packages/keditor/examples/snippets/snippets.html") }}',
        containerSettingEnabled: true,
        extraTopbarItems: {
            pageSetting: {
                html: '<a href="javascript:void(0);" class="btn-page-setting" data-extra-setting="pageSetting"><i class="fa fa-fw fa-cog"></i></a>'
            },
            pageHtml: {
                html: '<a href="javascript:void(0);" class="view-content"><i class="fa fa-fw fa-code"></i></a>'
            }
        },
        extraSettings: {
            pageSetting: {
                title: 'Page Settings',
                trigger: '.btn-page-setting',
                settingInitFunction: function (form, keditor) {
                    form.append('<div>This is content of page settings.</div><hr />');
                },
                settingShowFunction: function (form, container, keditor) {
                    form.append('<p>This content is added when showing setting</p><br />');
                }
            }
          }
      });

After that I tried

        KEditor.prototype.setContent(content); with no selectors
        KEditor.prototype.setContent(content, '#contentarea');
        KEditor.prototype.setContent(content, '#contentarea #subelement ');
         $('#contentarea').keditor('setContent', 'content goes here')
        $('#contentarea #subelement').keditor('setContent', 'content goes here')

if I use #contentarea as my selector I get self.error is not defined as contentArea is not defined. Weird how I am able to get the content with this selector but not set it.

I researched a bug fix here and it said set content on subelement. I used different classes and ids and I get an error can't addClass() to the element form initContentAreaClass.

If I manipulate the iframe and set contents on the keditor-iframe and it worked visually, but editor content was not set. I don't know where the conflict is but can't even set the content to a default paragraph when I load it. Why is it working for me? Am I doing something wrong here? I am using the ckeditor plugin . setData and getData from ckeditor is so easy from my past experience so I don't know why keditor set content won't work. get content is working for me

umutcodec commented 5 years ago

same thing with here also, setcontent doesnt work, i even tried setcontent example in your document and didnt work also. i am having same error: ncaught TypeError: self.error is not a function

yoganhoho commented 5 years ago

hi @nivanmorgan @umutcodec do you guys find any luck on this? I have same issue here. I can get content but cannot set.

sibox1337 commented 5 years ago

hi @nivanmorgan, do you find how to do it because i still cant use setContent, @ducdhm can u help us

ducdhm commented 5 years ago

@nivanmorgan @umutcodec @yoganhoho @sibox1337 I have fixed this issue. Please check with latest version.

FYI: Please call method of KEditor follow this guide

KEditor.prototype.setContent(content); with no selectors
KEditor.prototype.setContent(content, '#contentarea');
KEditor.prototype.setContent(content, '#contentarea #subelement ');

They are invalid calls!