diff --git a/src/main/resources/static/js/pages/index/frontend/indexUI.js b/src/main/resources/static/js/pages/index/frontend/indexUI.js index fdd9764..4728daf 100644 --- a/src/main/resources/static/js/pages/index/frontend/indexUI.js +++ b/src/main/resources/static/js/pages/index/frontend/indexUI.js @@ -10,3 +10,33 @@ export function addList(listAsJSON) { export function deleteList(listElement) { listElement.remove(); } + +export function createEditListForm(textElement) { + const editForm = document.createElement("form"); + const inputName = document.createElement("input"); + const abortButton = document.createElement("button"); + const saveButton = document.createElement("button"); + + inputName.setAttribute("name", "newListName"); + inputName.setAttribute("value", textElement.querySelector(".list__name").textContent); + inputName.classList.add("editForm__name"); + + abortButton.textContent = "Abbrechen"; + saveButton.textContent = "Speichern"; + + editForm.appendChild(inputName); + editForm.appendChild(saveButton); + editForm.appendChild(abortButton); + + return editForm; +} + +export function editList(id, formElement, formData, listLi) { + + let newName = formData.newListName; + + listLi.querySelector(".list__name").textContent = newName; + listLi.setAttribute("href", `/list/${id}`); + formElement.replaceWith(listLi); + +}