Skip to content

Commit

Permalink
Merge pull request #31 from taqui-786/main
Browse files Browse the repository at this point in the history
#29 Added Date and Time [Feature] and Fixed Edit button [BUG] .
  • Loading branch information
Kritika30032002 authored Oct 2, 2023
2 parents da0f729 + 3eea39c commit 6eb99ec
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function markAsComplete(e) {
function tasksCheck() {
// This function checks if ul contains children or not. According to that it add or removes hidden class
const tasksHeading = document.getElementById("heading-tasks");
const ulElement = document.querySelector("#items");
const ulElement = document.getElementById("items");
const children = ulElement.children;


Expand All @@ -33,16 +33,17 @@ window.onload = () => {
};

let editItem = null;

function addItem(e) {
e.preventDefault();

if (submit.value !== "Submit") {
editItem.target.parentElement.childNodes[2].textContent = document.getElementById("item").value;
editItem.target.parentElement.childNodes[1].textContent = document.getElementById("item").value;
submit.value = "Submit";
document.getElementById("item").value = "";

displaySuccessMessage("Text edited successfully");
editItem = null; // Reset editItem after editing
editItem = null;
return false;
}
tasksCheck()
Expand All @@ -66,20 +67,32 @@ function addItem(e) {
editButton.className = "btn btn-success btn-sm float-right edit";
editButton.appendChild(document.createTextNode("Edit"));
editButton.style.marginRight = "8px";

// Create a click event listener for the edit button
editButton.addEventListener("click", function (e) {
handleItemClick(e);
handleEditClick(e);
});

// Get the current date and time
const creationDateTime = new Date().toLocaleString();

// Create a paragraph element to display the creation date and time
const dateTimeParagraph = document.createElement("p");
dateTimeParagraph.className = "text-muted";
dateTimeParagraph.style.fontSize = "15px"; // Set font size
dateTimeParagraph.style.margin = "0 19px"; // Set margin
dateTimeParagraph.appendChild(document.createTextNode("Created: " + creationDateTime));

li.appendChild(completeCheckbox);
li.appendChild(document.createTextNode(newItem));
li.appendChild(deleteButton);
li.appendChild(editButton);
li.appendChild(dateTimeParagraph);

items.appendChild(li);


}


function handleItemClick(e) {
if (e.target.classList.contains("delete")) {
const li = e.target.parentElement;
Expand All @@ -88,12 +101,14 @@ function handleItemClick(e) {
displaySuccessMessage("Text deleted successfully");
}
if (e.target.classList.contains("edit")) {
e.preventDefault();
document.getElementById("item").value = e.target.parentElement.childNodes[1].textContent.trim();
submit.value = "EDIT";
editItem = e;
}
}


function toggleButton(ref, btnID) {
document.getElementById(btnID).disabled = false;
}
Expand All @@ -105,4 +120,3 @@ function displaySuccessMessage(message) {
document.getElementById("lblsuccess").style.display = "none";
}, 3000);
}

0 comments on commit 6eb99ec

Please sign in to comment.