menu

Questions & Answers

Get the markdown contents of toast-ui/editor into an html field for POST

I can get the toast-ui/editor to render. I just can't connect it to the form submit.

In my app.js I have this where I am loading the component and adding a listener to catch the form submit and pass the value to a hidden field #content

const editor = new Editor({
  el: document.querySelector('#editor'),
  height: '600px',
  initialEditType: 'markdown',
  placeholder: 'Placeholder',
})

$(document).on("submit", "form", function(event) {
    document.querySelector('#content').value = editor.getMarkdown();
    $(window).off('beforeunload');
  });

I am trying to catch that data in a hidden input

<div id="editor"><div>
<input type="hidden" name="content" id="content">

But it is not getting there before submit. I think it is the on('submit..... section of my javascript is the issue, but I am not sure what I am doing wrong there.

Comments:
2023-01-18 23:30:03
I have tried adding my script to the end of the html file, but that didn't work. It still cannot find my <input type='hidden' id='content'>
Answers(0) :