File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 2626 />
2727 </ div >
2828 < div >
29- < button type ="submit " class ="btn btn-primary mt-2 "> Add Todo</ button >
29+ < button type ="button " id ="add-btn " class ="btn btn-primary mt-2 ">
30+ Add Todo
31+ </ button >
3032 < button
3133 type ="button "
3234 id ="remove-all-completed "
Original file line number Diff line number Diff line change @@ -60,20 +60,23 @@ function addNewTodo(event) {
6060 let input = document . getElementById ( "todoInput" ) ;
6161 let newTask = input . value . trim ( ) ;
6262
63+ if ( newTask === "" ) {
64+ alert ( "Input field cannot be empty." ) ;
65+ return ;
66+ }
67+
6368 if ( / [ ^ A - Z a - z \s ] / . test ( newTask ) ) {
6469 alert ( "Please enter letters and spaces only." ) ;
6570 input . value = "" ;
6671 return ;
6772 }
6873
69- if ( newTask !== "" ) {
70- todos . push ( { task : newTask , completed : false } ) ;
71- populateTodoList ( todos ) ;
72- input . value = "" ;
73- }
74+ todos . push ( { task : newTask , completed : false } ) ;
75+ populateTodoList ( todos ) ;
76+ input . value = "" ;
7477}
7578
76- document . getElementById ( "todo-form " ) . addEventListener ( "submit " , addNewTodo ) ;
79+ document . getElementById ( "add-btn " ) . addEventListener ( "click " , addNewTodo ) ;
7780document
7881 . getElementById ( "remove-all-completed" )
7982 . addEventListener ( "click" , deleteAllCompletedTodos ) ;
You can’t perform that action at this time.
0 commit comments