agusmakmun / agusmakmun/django-markdown-editor

Rendering forms via Javascript

Open
#16 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
901
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.