agusmakmun / agusmakmun/django-markdown-editor

Rendering forms via Javascript

未关闭
#16 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
901
派生
1.3k
PR 合并指标
30 天内没有已合并 PR

描述

Hi. Currently the template I've written will generate one editor at the top which serves its purpose, however, when I click on a "Reply" button on the page I want another markdown editor form to be appended below.

I've currently tried cloning the form above and changing the ids to avoid conflicts however this renders the form unusable altogether (cannot type, button clicks on the editor do nothing). If I include two forms in the template (so not generated by Javascript) any buttons I click on the second editor will only ever make changes to the 1st editor.

I currently suspect most of these issues are due to the handlers on the Javascript files provided and was wondering if there was a potential workaround without having to change the JS files?

Below is the code in the HTML template which renders the current editor at the top of the page (works correctly)
```

{% csrf_token %}
{% for field in comment_form %}


{{ field }}


{% endfor %}
Post Comment

```

Below is the JS function which when the reply button is pressed is called. It should append the editor to div tag provided, whilst adding a user mention preloaded into the editor. The code below was from my attempt of cloning the editor already on the page using jQuery.
```
function generateReplyForm(commentIdAppendTo) {
const userReplyTo = $(`#${commentIdAppendTo}`).children('.comment-author-username').html();

let newForm = $('#comment-post-form').clone().removeAttr('id');
newForm.find('.ace_content').text(`@${userReplyTo}`);
newForm.find('#martor-content').attr('id', `#martor-content${commentIdAppendTo}`);
newForm.find('#id_content').attr('id', `#id_content${commentIdAppendTo}`);
$(`#${commentIdAppendTo}`).append(newForm);
}
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。