엄지월드

CK Editor5 글 수정 본문

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

 

'Front' 카테고리의 다른 글

javascript checkbox 값 가져오기  (0) 2023.01.10
CSS 버튼 색 추가  (0) 2022.11.24
An invalid form control with name='contents' is not focusable.  (0) 2022.08.23
로딩바 만들기  (0) 2022.07.27
table tr 제거  (0) 2022.07.27
Comments