Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c6b92c5

Browse files
working on edit note functionality
1 parent 63ffab3 commit c6b92c5

File tree

2 files changed

+67
-24
lines changed

2 files changed

+67
-24
lines changed

‎index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ <h2 class=" ml3 mt-5 mb-2"><span class="letters">Welcome to NoteFizz App</span><
4747
<div class="form-group">
4848
<div class="title-area my-4">
4949

50-
<input type="text" onkeyup="unique_notes_verifier()" class="form-control mt-3" id="note_title" placeholder="Note Title">
50+
<input type="text" class="form-control mt-3" id="note_title" placeholder="Note Title">
5151
<p id="title_error"></p>
5252
</div>
5353
<div class="data-area my-4">

‎js/script.js

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ function data_validator() {
7070
if (data_el == "") {
7171
error_message_shower(false, "Note Data Can't be Empty");
7272
} else {
73-
add_note(title_el, data_el);
74-
save_to_local(storenote, title_el, data_el);
73+
if(unique_notes_verifier())
74+
{add_note(title_el, data_el);
75+
save_to_local(storenote, title_el, data_el);}
7576
}
7677
}
7778
//////////////add note fuction ////////////////////////
@@ -156,29 +157,46 @@ function saved_notes_display() {
156157
}
157158
}
158159
function unique_notes_verifier() {
160+
159161
input = document.getElementById("note_title").value;
160-
/////////////////////verify if it is in dom///////////////////
161-
cardsTitle = document.getElementsByClassName("card-title");
162-
163-
cardsTitle_li = [];
164-
Array.from(cardsTitle).forEach(function (element, ind) {
165-
cardsTitle_li.push(element.innerHTML);
166-
});
167-
for (let j = 0; j < cardsTitle_li.length; j++) {
168-
if (cardsTitle_li[j].toLowerCase().indexOf(input.toLowerCase()) > -1) {
169-
error_message_shower("Title Already Exist");
170-
document.getElementById("addbtn").disabled=true;
171-
} else {
162+
163+
/////////////////////verify if it is in dom///////////////////
164+
let noteselm = JSON.parse(localStorage.getItem("notes"));
165+
try
166+
{
167+
noteselm.forEach(function note_data_extractor(note, ind) {
168+
for (var title in note)
169+
{
170+
171+
if(title.toLowerCase()==input.toLowerCase())
172+
{
173+
174+
error_message_shower("Title Already Exist");
175+
throw "Title Already Exist"
176+
177+
178+
}
179+
}
180+
});
172181
terror = document.getElementById("title_error");
173-
terror.innerHTML = "";
174-
terror.setAttribute("style", "color: red; font-size: 12px;");
175-
t_el = document
176-
.getElementById("note_title")
177-
.setAttribute("style", "border: 1px solid green;");
178-
document.getElementById("addbtn").disabled=false;
179-
180-
}
182+
183+
terror.innerHTML = "";
184+
terror.setAttribute("style", "color: red; font-size: 12px;");
185+
t_el = document
186+
.getElementById("note_title")
187+
.setAttribute("style", "border: 1px solid green;");
188+
document
189+
.getElementById("note_data")
190+
.setAttribute("style", "border: 1px solid green;");
191+
192+
return true;
181193
}
194+
catch(err)
195+
{
196+
return false;
197+
}
198+
199+
182200
}
183201
//////////////////this will clear your local storage////////////////////
184202
function localStorage_clear() {
@@ -227,12 +245,37 @@ function note_search(e) {
227245
function edit_note(id)
228246
{
229247
title = document.getElementById("note_title");
248+
230249
data = document.getElementById("note_data");
250+
231251
note = document.getElementById(id).children[0].children[1];
252+
232253
title.value=note.children[0].innerText;
233254
data.value = note.children[1].innerText;
234-
console.log(id)
255+
256+
addbtn = document.getElementById("addbtn");
257+
258+
savebtn = document.createElement('button');
259+
savebtn.innerHTML="Save Note"
260+
savebtn.setAttribute('id',"savebtn")
261+
savebtn.setAttribute('class',"btn btn-dark")
262+
savebtn.setAttribute('onclick',"edit_save()")
263+
addbtn.replaceWith(savebtn);
264+
265+
266+
267+
235268

269+
}
270+
function edit_save()
271+
{
272+
oldnote = document.getElementById(id).children[0];
273+
title = document.getElementById("note_title").value;
274+
275+
data = document.getElementById("note_data").value;
276+
let noteselm = JSON.parse(localStorage.getItem("notes"));
277+
console.log(noteselm)
278+
savebtn.replaceWith(addbtn)
236279

237280

238281
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /