проблем с 01. Forum posts от JS Advanced Retake Exam - 6 April 2022
Здравейте, получавам 50/100 и новосъздадените бутони не работят, някой може ли да ми помогне ?
задача: https://judge.softuni.org/Contests/Practice/Index/3425#0
код:
function solve() {
let fields = Array.from(document.querySelectorAll('input')).slice(0, 2)
let contentEl = document.getElementById("post-content")
let addBtnEl = document.getElementById("publish-btn")
let clearBtnEl = document.getElementById("clear-btn")
let reviewSection = document.querySelector("#review-list");
let publSection = document.querySelector('#published-list');
clearBtnEl.addEventListener('click',onClear)
function onClear(e){
e.preventDefault();
publSection.innerHTML = ''
}
addBtnEl.addEventListener('click',onNext)
function onNext(e) {
e.preventDefault();
let[titleArr, categoryArr] = fields
if(!titleArr.value || !categoryArr.value || !contentEl.value) {
return;
}
const el = document.createElement('li');
el.setAttribute('class', 'rpost')
el.innerHTML = `
<article>
<h4>${titleArr.value}</h4>
<p>Category: ${categoryArr.value}</p>
<p>Content: ${contentEl.value}</p>
</article>
<button class="action-btn edit">Edit</button>
<button class="action-btn approve">Approve</button>
`
reviewSection.appendChild(el)
let editTitle = titleArr.value;
let editCategory = categoryArr.value;
let editPost = contentEl.value;
fields.forEach(x => x.value = '')
contentEl.value = ""
addBtnEl.disabled = true;
el.querySelector('.action-btn edit').addEventListener("click", onEdit);
function onEdit() {
titleArr.value = editTitle;
categoryArr.value = editCategory;
contentEl.value = editPost;
reviewSection.innerHTML = ''
addBtnEl.disabled = false;
}
el.querySelector('.action-btn approve').addEventListener('click', onContinue);
function onContinue() {
publSection.innerHTML = `<li class="approve-content">
<article>
<h4>${titleArr.value}</h4>
<p>Category: ${categoryArr.value}</p>
<p>Content: ${contentEl.value}</p>
</article>
</li>
`
reviewSection.innerHTML = ''
}
}
}
Благодаря !