0

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?

2
  • 2
    have you tried adding a ng-model? putting your code directly into a fiddle shows the message: jsfiddle.net/9yp75kr3 Commented Sep 3, 2014 at 1:36
  • I feel worldwide shame... Commented Oct 10, 2014 at 2:03

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Now, I really feel dumb. Thanks @jcruz, it worked as expected.

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.