Luke Skywalker
Luke Skywalker

Reputation: 1521

Angular input validity property without a form

I have inputs in a web page without the form tag (useless to me). How can I get their validity status inside the HTML ? This

<input name="myInput" type="text" ng-pattern="/^[0-9]{13}$/">
<input type="button" ng-show="myInput.$valid">

doesn't work.

Upvotes: 0

Views: 549

Answers (1)

ivarni
ivarni

Reputation: 17878

I'm afraid that won't work without wrapping it in a form as you need to access those fields via the form's controller.

<form name="myForm">
    <input name="myInput" type="text" ng-pattern="/^[0-9]{13}$/">
    <input type="button" ng-show="myForm.myInput.$valid">
</form>

Should work.

If you're unable to use the form tag for any reason, you'll have to wire that up manually.

Upvotes: 1

Related Questions