1

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/

1
  • take a look at my answer Commented Aug 4, 2015 at 10:19

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.