-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
94 lines (75 loc) · 2.28 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
let tasks = document.getElementById("tasks");
let add = document.getElementById("add");
let form = document.getElementById("form");
let textInput = document.getElementById("textInput");
let dateInput = document.getElementById("dateInput");
let textarea = document.getElementById("textarea");
let msg = document.getElementById("msg");
form.addEventListener("submit", (e) => {
e.preventDefault()
console.log("Button Clicked")
Validation()
})
let Validation = () => {
if(textInput.value === ""){
msg.innerHTML = "Blank cannot be blank"
}else{
console.log("sucesses")
msg.innerHTML = ""
acceptData()
add.setAttribute("data-bs-dismiss", "modal")
add.click();
(() => {
add.setAttribute("data-bs-dismiss", "");
})();
}
}
let databank = [];
let acceptData = () => {
databank.push({
text: textInput.value,
date: dateInput.value,
area: textarea.value,
})
localStorage.setItem("data", JSON.stringify(databank))
console.log(databank)
createForm()
}
let createForm = () => {
tasks.innerHTML = "";
databank.map((x,y) => {
return tasks.innerHTML += `
<div id=${y}>
<span class="fw-bold">${x.text}</span>
<span class="small text-secondary">${x.date}</span>
<p>${x.area}</p>
<span class="options">
<i onClick= "editForm(this)" data-bs-toggle="modal" data-bs-target="#form" class="fas fa-edit"></i>
<i onClick ="deleteForm(this);createTask()" class="fas fa-trash-alt"></i>
</span>
</div>`;
})
resetForm();
}
let resetForm = () => {
textInput.value = "";
dateInput.value = "";
textarea.value = "";
}
let deleteForm = (e) => {
e.parentElement.parentElement.remove()
databank.splice(e.parentElement.parentElement.remove(), 1)
localStorage.setItem("data", JSON.stringify(databank))
console.log(databank)
};
let editForm = (e) => {
let selTask = e.parentElement.parentElement;
textInput.value = selTask.children[0].innerHTML;
dateInput.value = selTask.children[1].innerHTML;
textarea.value = selTask.children[2].innerHTML;
deleteForm(e)
};
(() =>{
databank = JSON.parse(localStorage.getItem("data")) || [];
createForm()
})();