mkhstar / suneditor-react

A React Component for SunEditor (WYSIWYG editor)
http://suneditor.com/
427 stars 105 forks source link

How to reset already typed or inputed data after form submit? #305

Closed siamahnaf closed 1 year ago

siamahnaf commented 1 year ago

Hello, I am not finding any options in docs to reset editor. I need to reset whole editor when form is submited. Can you give me direction about this.


<SunEditor
    placeholder="Please type here..."
    setOptions={{
        buttonList: [["undo", "redo"], ["font", "fontSize", "formatBlock"], ["paragraphStyle", "blockquote"], ["bold", "underline", "italic", "strike", "subscript", "superscript"], ["fontColor", "hiliteColor", "textStyle"], ["removeFormat"], ["outdent", "indent"], ["align", "horizontalRule", "list", "lineHeight"], ["table", "link", "codeView", "showBlocks"], ["preview", "fullScreen"]]
    }}
    setDefaultStyle="font-family: Arial; font-size: 16px;"
    height="180px"
    onChange={onChange}
    name="description"
    defaultValue={value}
/>
mkhstar commented 1 year ago

@siamahnaf with this you can use setContents instead of defaultValue.

<SunEditor
    placeholder="Please type here..."
    setOptions={{
        buttonList: [["undo", "redo"], ["font", "fontSize", "formatBlock"], ["paragraphStyle", "blockquote"], ["bold", "underline", "italic", "strike", "subscript", "superscript"], ["fontColor", "hiliteColor", "textStyle"], ["removeFormat"], ["outdent", "indent"], ["align", "horizontalRule", "list", "lineHeight"], ["table", "link", "codeView", "showBlocks"], ["preview", "fullScreen"]]
    }}
    setDefaultStyle="font-family: Arial; font-size: 16px;"
    height="180px"
    onChange={onChange}
    name="description"
    setContents={value}
/>

After you want to clear

// lets say value can be changed from state
setValue('')