简体   繁体   English

将 toast-ui/editor 的 markdown 内容获取到 html 字段以进行 POST

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

I can get the toast-ui/editor to render.我可以让 toast-ui/editor 渲染。 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在我的 app.js 中,我在其中加载组件并添加一个侦听器以捕获表单提交并将值传递给隐藏字段#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.我认为这是 on('submit..... 我的 javascript 的部分是问题,但我不确定我在那里做错了什么。

The issue is that the hidden input field was within the same div as the editor div.问题是隐藏的输入字段与编辑器 div 在同一个 div 中。 It does something to the parent div that gets rid of the other tags in the same parent.它对父 div 做了一些事情,摆脱了同一父级中的其他标签。

Also, for some reason adding value to the input doesn't put it in the value field but appends it after the field.此外,出于某种原因,向输入添加值不会将其放入值字段中,而是将其附加到该字段之后。 Don't know why.不知道为什么。

<textarea class='hidden' name="content" id="content">{{ old("content")}}</textarea>
<div>
  <div id="editor"><div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM