Rubens Mariuzzo
Rubens Mariuzzo

Reputation: 29261

How to make an input type=date required using AngularJS?

I'm using Angular 1.2.23 and I would like to make a input type=date required, I have the following code:

<form name="form" novalidate>
    <input id="date" name="date" type="date" required />
    <span ng-show="form.date.$error.required">The date is required!</span>
</form>

plnkr

The span with the message doesn't appear, why?


If input type date are not supported in Angular 1.2.23, is there any good alternative to validate?

Upvotes: 0

Views: 1677

Answers (1)

jcruz
jcruz

Reputation: 718

you need to bind your input field to a value in your scope using the ngModel directive

Here is an updated plunkr

http://plnkr.co/edit/orhtCBL295atga5jsT6p?p=preview

  <form name="form" novalidate>
    <input id="date" name="date" type="date" ng-model="date" required />
    <span ng-show="form.date.$error.required">The date is required!</span>
  </form>

Upvotes: 4

Related Questions