Tui.editor: Question : how to save ?

Created on 12 Jan 2018  ·  6Comments  ·  Source: nhn/tui.editor

Hi !

Not an issue but a question : I've not yet installed tui.editor and I'm really interested too try it but ... how can we save the content on the server ?

I'm actually using Simple MDE, we can attach on the toolbar a "save" button, retrieve the content of the

and send it to the server with Ajax f.i.

Can we does something like that with tui.editor ? Can you provide tips or documentation ?

Many thanks !!!

Christophe

Question

Most helpful comment

I hope this helps you out:

const Editor = TuiEditor.factory({
      el: this.el,
      height: 'auto',
      initialValue: determineValue(this.props),
      initialEditType: 'wysiwyg',
      events: {
        change: this.onChange,
        focus: () => onFocus(),
        blur: () => onBlur(),
      },
})

then for example in your onChange method, youd do this:

    const value = Editor.getMarkdown();

or

    const value = Editor.getHtml();

All 6 comments

It just replaces a form-element or div etc. You can save your data like you prefer doing it with other input elements

Thanks for the very fast answer.

So, to take a real example, on the demo page (https://nhnent.github.io/tui.editor/), I click on the "Features" div, type something and see in the DOM inspector that the change is done in the div with class "te-editor" like :

<div class="te-editor" style="position: relative;">
    <div contenteditable="true">
        <h1>
            <div>
                <span class="colour" style="color:rgb(75, 148, 229)">Features MY CHANGES</span>
            </div>
        </h1>

Should I foresee a .onChange() js function on that DOM elem to retrieve the change ? (how can I very quickly remove the "

" and only retrieve the editor's content).

Thanks

I hope this helps you out:

const Editor = TuiEditor.factory({
      el: this.el,
      height: 'auto',
      initialValue: determineValue(this.props),
      initialEditType: 'wysiwyg',
      events: {
        change: this.onChange,
        focus: () => onFocus(),
        blur: () => onBlur(),
      },
})

then for example in your onChange method, youd do this:

    const value = Editor.getMarkdown();

or

    const value = Editor.getHtml();

@skerbis @michaelryancaputo Thanks guys. I see we have good contributors 💯

@cavo789 in addition, you can check out API Docs constructor options

I'm closing it.

Thank you guys !!! Thank you Michael for your js code 👍

Thank you guys!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nilhave picture nilhave  ·  3Comments

alirizaadiyahsi picture alirizaadiyahsi  ·  4Comments

koliyo picture koliyo  ·  4Comments

cyberjacob picture cyberjacob  ·  4Comments

aarangara picture aarangara  ·  3Comments