Preventing Text Submission In Controller Failing

Astin

New Member
I'm running a simple example from the main page of Angular involving a todo list. I want to prevent the user from submitting a todo when the input field is blank. The problem is when I load the page and the first thing I do is I click inside the input field and press enter, then the blank todo is added the Todo list. However, after that the validation works. I know there are other ways of doing this, but I want to know why this bug exists and how to fix it.My html below\[code\]<form ng-submit="addTodo()"> <input ng-model="todoText" placeholder="Add a todo here" type="text" /> <input class="button" type="submit" value="http://stackoverflow.com/questions/14063840/add"></form>\[/code\]My js file\[code\]$scope.addTodo = function() { if ($scope.todoText != "") { $scope.todos.push({text:$scope.todoText, done:false}); $scope.todoText = ''; }};\[/code\]
 
Back
Top