vanilla-todo icon indicating copy to clipboard operation
vanilla-todo copied to clipboard

Empty field can be submitted

Open tusharb05 opened this issue 3 years ago • 3 comments

tusharb05 avatar Jun 02 '21 17:06 tusharb05

Solution might be: Adding .trim() after grabbing the value from that field

tusharb05 avatar Jun 02 '21 17:06 tusharb05

Hello tusharb,

Just simply add this code underneath first function addTodo(event) after event.preventDefault() function.

if (mainInput.value === ' ') { alert('You have to specify your task first.'); return false; }

This code will simply inform you, that the input value cannot be empty string or null value. It will return false, what means it will stop code from executing any further.

ghost avatar Jul 28 '21 12:07 ghost

If you are working on the react project, in the Form components you can change the submitTodoHandler as follows

const submitTodoHandler = (e) => { e.preventDefault(); console.log(inputText); if(!(inputText === "")) { setTodos([ ...todos, {text: inputText, completed: false, id: Math.random()*1000 }, ]); setInputText(""); }else{ alert("Kindly specify your task first."); } };

AmeerZeya avatar May 13 '22 07:05 AmeerZeya