2

I am trying to validate a single input to check numbers 1-99, I am wondering if I can do this in angular without having it wrapped in a form. Not a problem if it needs a form, just curious if it has to have it. Here's what I'm attempting -

<div class="errorMulti" ng-show="multiAdd.$error.maxlength">Error</div>
<input type='text' ng-model="multiAdd" placeholder='Number of levels to add 1-99' ng-maxlength="2"> 

Pretty straight forward, but doesn't seem to work. Any insight? thanks!

4
  • is there a reason to use input without a form? is any reason to do that? Commented Sep 8, 2014 at 13:49
  • None, just curious if you can. Commented Sep 8, 2014 at 13:59
  • can use ng-form also without form tag, see docs Commented Sep 8, 2014 at 14:06
  • possible duplicate of AngularJS <input> validation with no enclosing <form> Commented Sep 8, 2014 at 14:09

1 Answer 1

-2
<div ng-app>
   <form name="myform">
    <div class="errorMulti" ng-show="myform.multiAdd.$error.maxlength">Error</div>
    <input type='text' name="multiAdd" ng-model="multiAdd" placeholder='Number of levels to add 1-99' ng-maxlength="2">
    </form>
 </div>

Check the JSfiddle: http://jsfiddle.net/15ugz6j3/

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

1 Comment

I don't understand how this can be the accepted answer. The question is "How do I validate outside forms" and your answer is "wrap it in a form"?????

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.