Add a function to solve the extra input bug when manipulating comments

This commit is contained in:
William Karsten 2022-06-09 15:24:28 -05:00
parent 1d02c1b316
commit db34fa723a
1 changed files with 9 additions and 1 deletions

View File

@ -501,6 +501,12 @@ const fetchWithCSRF = (url, params) => {
return fetch(url, params);
}
const removeExtraInput = (targetElement) => {
// This deletion will resovle a bug that creates an extra hidden input when rendering the comment elements.
const extraInput2 = targetElement.parentElement.querySelector('.comment_folder_button');
extraInput2.remove();
}
onPageLoad(() => {
// Global Functions
@ -586,13 +592,15 @@ onPageLoad(() => {
fetch('/comments/' + comment.getAttribute('data-shortid') + '/edit')
.then(response => {
response.text().then(text => replace(comment, text));
});
});
removeExtraInput(comment);
});
on("click", "a.comment_deletor", (event) => {
event.preventDefault();
if (confirm("Are you sure you want to delete this comment?")) {
const comment = parentSelector(event.target, ".comment");
removeExtraInput(comment);
const commentId = comment.getAttribute('data-shortid');
fetchWithCSRF('/comments/' + commentId + '/delete',{method: 'post'})
.then(response => {