tinymce / tinymce-webcomponent

MIT License
15 stars 7 forks source link

setting and retrieving content #4

Closed rrrepos closed 3 years ago

rrrepos commented 3 years ago

I have been wanting to use the webcomponent version of tinymce and have been able to successful add it to a webpage. However, I did not find a way (attribute) to set content or retrieve content to the component.

In my use-case I am adding it as a component within my own custom webcomponent that has other editing components as well (such as file input etc)

Thanks

jscasca commented 3 years ago

Hi @rrrepos

I think you should be able to get/set the value content of the editor by using the element value as with any other input element. E.G.:

document.getElementById('my-editor').value = '<p>new content</p>';
console.log(document.getElementById('my-editor').value)
rrrepos commented 3 years ago

Ah yes ... as simple as that :+1: However, the following error seems to show on the console

Uncaught TypeError: Cannot read property 'toString' of undefined
    at Object.isEditorUIElement (tinymce.min.js:2)
    at tinymce.min.js:2
    at E (tinymce.min.js:2)
    at Object.getParent (tinymce.min.js:2)
    at am (tinymce.min.js:2)
    at tinymce.min.js:2
    at Object.each (tinymce.min.js:2)
    at Object.hd (tinymce.min.js:2)
    at Ei.executeHandlers (tinymce.min.js:2)
    at HTMLDocument.s (tinymce.min.js:2)

The html is:

`

`

jscasca commented 3 years ago

Sorry @rrrepos I have tried replicating that behaviour without luck. Can you elaborate a bit more on the circumstances when that happens? Does it happens every time?

rrrepos commented 3 years ago

Let me check it again @jscasca and share more details of it. Thanks

jscasca commented 3 years ago

I'm closing the issue due to a lack of activity but feel free to reopen if you are still experiencing issues with the component