Front

CK Editor5 글 수정

킨글 2022. 12. 11. 09:44

[문제]

CK Editor5를 적용해서 글쓰기는 성공했지만,
수정 시에 document.getElementById("editor").value;로 값을 읽어오지 못하는 현상이 있었다. 

그래서 CK Editor Document를 확인해보니 다른 방법으로 처리하고 있었다. 

[해결 방법]

에디터가 생성되기 전에 let editor로 선언한 후에 

then 흐름을 통해 let editor에 newEditor 객체를 집어넣는다. 

 

그 후에 submit 이벤트가 발생했을 때에 editor.getDat()로 읽어오면 수정한 데이터를 읽어올 수 있다. 

let editor;

ClassicEditor
    .create( document.querySelector( '#editor' ) )
    .then( newEditor => {
        editor = newEditor;
    } )
    .catch( error => {
        console.error( error );
    } );

// Assuming there is a <button id="submit">Submit</button> in your application.
document.querySelector( '#submit' ).addEventListener( 'click', () => {
    const editorData = editor.getData();

    // ...
} );

 

Reference > CK Document Link