agusmakmun / agusmakmun/django-markdown-editor

Rendering forms via Javascript

Ouverte
#16 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
901
Forks
1.3k
Métriques de merge des PR
Aucune PR mergée en 30 j

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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.