codex-team / editor.js

A block-style editor with clean JSON output
https://editorjs.io
Apache License 2.0
28.18k stars 2.06k forks source link

[Bug] Save function not working - editor.save is not a function #1136

Open zizther opened 4 years ago

zizther commented 4 years ago

Calling the .save() function does not work, with the console error saying Uncaught TypeError: editor.save is not a function

I have tried several ways to to initialise editor.js, even with the examples from the docs (https://editorjs.io/saving-data), it still displays the error.

const editor = new EditorJS();

editor.save().then((outputData) => {
  console.log('Article data: ', outputData)
}).catch((error) => {
  console.log('Saving failed: ', error)
});

The only other JS library being used is jQuery.

Any thoughts on how I can get this working, or help debug? Thanks


Editor.js version: 2.17.0

Plugins you use with their versions: Header Quote Delimiter

sis-dk commented 4 years ago

Can you give a code sandbox link with your code reproducing the issue?

zizther commented 4 years ago

Here a codepen example - https://codepen.io/zizther/pen/oNjGeGb?editors=1010

I have included jQuery as it is in my example, but you can replicate the same issue without jQuery. I have just used the code example from the docs.

sis-dk commented 4 years ago

You will have to wait for editor to become ready first https://editorjs.io/configuration#use-isready-promise

zizther commented 4 years ago

Got ya. You can place it in the onReady callback or listen to the isReady promise.

Would be nice for that to be clearer in the docs.