agusmakmun / agusmakmun/django-markdown-editor

Rendering forms via Javascript

Đang mở
#16 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
901
Fork
1.3k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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);
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.