How can I set the maximum value in my html5 date input so that it can be recognized by iOS safari?

The name is pretty clear, I think?

Here is my date entry:

<input type="date" id="birthdate" name="birthdate" value="" max="1993-12-07" required/> 

In chrome, I cannot enter a date other than 1993-12-07 using the small arrows of the field (but if I write the date myself, I can).

In iOS Safari, focusing on this field simply brings a good date picker. However, this date parameter is not limited to the max attribute. So how can I do this? Of course, I have a server side check, but I want to do it on the client side as well. Any ideas? Thanks!

+6
source share
3 answers

Safari does not yet support it. Only Opera and Chrome have supported it since November 2011. In any case, here is w3spec on it http://www.w3.org/TR/html-markup/input.date.html#input.date.attrs.max

You can use js check to submit or change. Use the js validation framework of your choice

Here's an example js http://www.roseindia.net/answers/viewqa/Ajax/4734-start-date-and-end-date-validation-in-javascript.html . Use the maximum date instead of the end date.

To solve jquery, see Confirm that the end date is longer than the start date with jQuery

+7
source

Found a solution to dynamically disable future dates:

 @{ string datestring = DateTime.Now.ToString("yyyy-MM-dd"); } <input type="date" required="required" name="AttendanceDate" max="@datestring" class="form-control" /> 
0
source

This is the year 2019, and safari still do not support them!

0
source

Source: https://habr.com/ru/post/903297/


All Articles