@@ -120,6 +120,10 @@ <h3 class="bg-success text-capitalize"> Hi There, {{user}}</h3>
120
120
< button type ="submit " class ="btn btn-primary " onclick ="submitToDo(event) "> Add New</ button >
121
121
</ div >
122
122
</ form >
123
+ < div class ="text-center card py-2 ">
124
+ < label for ="searchinput " class ="mr-4 "> Search ToDo</ label >
125
+ < input type ="text " name ="seach " id ="searchinput " oninput ="searchThis(event) ">
126
+ </ div >
123
127
< div id ="todoArea " class ="list-group "> </ div >
124
128
</ div >
125
129
</ div >
@@ -134,6 +138,12 @@ <h3 class="bg-success text-capitalize"> Hi There, {{user}}</h3>
134
138
var todoList ;
135
139
136
140
141
+ function searchThis ( event ) {
142
+ event . preventDefault ( )
143
+ createToDoList ( event . target . value )
144
+ }
145
+
146
+
137
147
// cokie validation
138
148
function getCookie ( name ) { // copied from django doc
139
149
if ( ! document . cookie ) {
@@ -176,7 +186,7 @@ <h3 class="bg-success text-capitalize"> Hi There, {{user}}</h3>
176
186
function submitToDo ( e ) {
177
187
e . preventDefault ( )
178
188
var dat = new FormData ( $ ( 'form' ) [ 0 ] )
179
- console . log ( '----------------------' , Object . fromEntries ( new FormData ( $ ( 'form' ) [ 0 ] ) ) )
189
+ // console.log('----------------------', Object.fromEntries(new FormData($('form')[0])))
180
190
181
191
182
192
fetch ( url , {
@@ -187,7 +197,7 @@ <h3 class="bg-success text-capitalize"> Hi There, {{user}}</h3>
187
197
body : dat
188
198
}
189
199
) . then ( function ( res ) {
190
- console . log ( res )
200
+ // console.log(res)
191
201
if ( res . status == 201 ) {
192
202
createToDoList ( )
193
203
$ ( 'form' ) [ 0 ] . reset ( ) ;
@@ -200,18 +210,19 @@ <h3 class="bg-success text-capitalize"> Hi There, {{user}}</h3>
200
210
201
211
202
212
// GET request, list all todos
203
- function createToDoList ( ) {
204
- fetch ( url ) . then ( res => res . json ( ) ) . then ( function ( data ) {
213
+ function createToDoList ( searchparams ) {
214
+ let slug = searchparams != undefined ? `?search=${ searchparams } ` : ''
215
+ fetch ( url + slug ) . then ( res => res . json ( ) ) . then ( function ( data ) {
205
216
var txt = ''
206
217
todoList = [ ]
207
- console . log ( data )
218
+ // console.log(data)
208
219
209
220
210
221
for ( let item of data ) {
211
222
let due = item . duedate ? `<label class="duedate">Due in ${ dtParser ( item . duedate ) } </label>` : ''
212
223
let date = item . completed ? `<label class="completedate">${ dtParser ( item . datecompleted ) } </label>` :due
213
224
214
- console . log ( item . completed )
225
+ // console.log(item.completed)
215
226
txt += `<div class='list-group-item todoitem ${ item . completed ? "checked" : "" } '>
216
227
<div class="inforow">
217
228
<div class="check-container">
@@ -279,7 +290,7 @@ <h3 class="bg-success text-capitalize"> Hi There, {{user}}</h3>
279
290
method : 'DELETE' ,
280
291
headers : headers ,
281
292
} ) . then ( function ( response ) {
282
- console . log ( response )
293
+ // console.log(response)
283
294
if ( response . status == 204 ) {
284
295
createToDoList ( )
285
296
}
0 commit comments