Ionaru / easy-markdown-editor

EasyMDE: A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.
https://stackblitz.com/edit/easymde
MIT License
2.39k stars 316 forks source link

Autosaved text is not forgotten after the form is submitted #257

Closed christophe-lejeune closed 3 years ago

christophe-lejeune commented 3 years ago

I use EasyMDE to allow students to record their essays at different stages, so that I can comment their results before they are completed. Students work in teams, which means that a single text may be modified by different people (only one at a time, of course). Since I have (recently) enabled autosave option, some students report me that they lose data when editing their essay.

Here is an illustrative case. After an essay is created (let's say that Amy wrote one paragraph and submitted it on the online platform), it is modified by another student (Barry wrote a second paragraph). The result is correctly recorded, so that Amy is able to read the whole on her computer. She decided to edit the essay and she is surprised to find, in the edit textarea, the essay she originally submitted (only one paragraph instead of two).

My understanding of what happens is that EasyMDE did not forget the content of the textarea when it is submitted... as if it considers that the text is not submitted yet. This is not a problem when one user works on the same computer with the same browser all the time. As soon as two different browsers/computers/users edit the same text, this behavior becomes an issue. However, it is likely that the issue comes from the way I am using EasyMDE . Here are some details.

  var easymde = new EasyMDE({
    element: $("#content")[0],
    autosave: {
      enabled: true,
      uniqueId: "abcdefg",
      delay: 1000,
    },
    toolbar: ["bold", "italic", "strikethrough", "|", "heading-3", "unordered-list", "horizontal-rule", "|", "link", "image", "table", "|", "guide"],
    placeholder: "Type your essay here",
    spellChecker: false
  })

At this stage, I have three hypotheses of what could be wrong:

  1. Perhaps the code of the button should contain some reference to a submit form, to ensure EasyMDE forgets the autosaved value when it is hit;
  2. Perhaps it is wrong to use easymde.value() as the content to be saved in the database. However, I think this comes from an example in the documentation... but I may be wrong;
  3. Perhaps I should explicitly force EasyMDE to forget (with easymde.clearAutosavedValue())... but, if I understand correctly, a simple usage like mine should not require this.

I thank you all for your advices, help and corrections. Christophe

nhymxu commented 3 years ago

I think you should control by yourself. Because many way to submit form and hard to catch this.

Sample:

christophe-lejeune commented 3 years ago

This is what I have done for my project.

@nhymxu Thank you very much for your answer !