DevT
DevT

Reputation: 1511

simple angular validation doesn't work

Why doesn't validation work? It's pretty simple:

<div ng-app ng-controller="formCtrl" >
    <form name="productForm" ng-submit="addCartItem()" novalidate >
       <input type="text" name="quantity" ng-maxlength="2" required novalidate />
        <span class="error" ng-show="productForm.quantity.$error.required">Required!</span>
        <input id="submitProductForm" type="submit"  />
    </form>
</div>

function formCtrl($scope){
    $scope.addCartItem = function(){
        alert(productForm.$error);
    }
}

Here the link to jsfiddle: http://jsfiddle.net/ogwsa5wn/

Upvotes: 1

Views: 1653

Answers (1)

Nidhish Krishnan
Nidhish Krishnan

Reputation: 20751

you have forgot to add ng-model to input textfield

just use

<input type="text" ng-model="quantity" name="quantity" ng-maxlength="2" required novalidate />

instead of

<input type="text" name="quantity" ng-maxlength="2" required novalidate />

Working JSfiddle

Upvotes: 4

Related Questions