Reputation: 127
I referred Angular JS Form validation inside tabset give error : TypeError: Cannot read property '$valid' of undefined but its not exactly what am looking for.
I have this html code,
<form name="userForm" ng-submit="submit()" novalidate>
<input type="text" class="form-control" ng-model="user.name" required>
<button type="submit" class="btn btn-primary" ng-disabled="!userForm.$valid">Submit</button>
</form>
And my js is something like,
$scope.submitForm = function () {
// check to make sure the form is completely valid
if ($scope.userForm.$valid) {
alert('its working');
}
};
I get this error. Is there a way to resolve this when am using ng-submit
.
Upvotes: 0
Views: 1711
Reputation: 4109
Could you please try the code below:
$scope.submitForm = function() {
// check to make sure the form is completely valid
if (userForm.$valid) {
alert('its working');
}
};
I removed $scope
from $scope.userForm.$valid
, because userForm is not a property of $scope
.
You could check the official AngularJS docs, especially this part, where you can see how they bind to the form.
Upvotes: 1