codex-team / editor.js

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

How to save editor.js at all time and places #1234

Closed stan900814 closed 4 years ago

stan900814 commented 4 years ago

i want to save the data all the times but there is no method ,also not have the blur event 。has any ways to get it?

neSpecc commented 4 years ago

What do you mean "all the times"?

neSpecc commented 4 years ago

The blur event is implemented and waiting for the code review

stan900814 commented 4 years ago

What do you mean "all the times"?

just like i edit a block it can immediately save this data

stan900814 commented 4 years ago

The blur event is implemented and waiting for the code review

how i can listening the keydown and keyup events in edtor.js

neSpecc commented 4 years ago

You can use the onChange callback where simply call the .save()

neSpecc commented 4 years ago

Answered

ShadowMyst commented 4 years ago

@neSpecc Could you give me an example of implementation with "onchange", since I can't find the way to use .save (), it gives me an error when I try it

neSpecc commented 4 years ago

@ShadowMyst See an example from our landing page

ShadowMyst commented 4 years ago

thanks you. based on the link you passed me I did this.

const editor = new EditorJS({
    holder: 'editorjs',
    autofocus: true,
    tools:{
        header:{
            class: Header,
            config:{
                placeholder: "Escriba el titulo",
                levels: [2,3,4,5,6],
                defaultLevel:2
            },
            inlineToolbar: true
        },
        list: {
            class: List,
            inlineToolbar:true,
        }
    },
    data:{},
    onReady: ()=>{

    },
    onChange:() =>{
        saved();
    }
});
function saved(){
    editor.save().then((savedData) =>{
        console.log('salvado',savedData);
    }).catch((error) =>{
        console.log("fallo al guardar",error)
    })
}