Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html 5 [input type=Date] control, MAX date is not working in iPhone/Ipad

Greetings.

Working with html date input control.

input type="date" max="2014-13-11"

In chrome its recognizing 'max'attribute hence restricting and disabling all future date

But, the same is not working in iPad/iphone. Instead its allowing to select future date in iPad.

Googled and came to know that ipad is not yet supporting Max attribute of date control.

Is there any work around? or any points / direction will be really help for me.

Many thanks. Karthik

like image 801
karthik Avatar asked Nov 14 '14 11:11

karthik


People also ask

Does Safari support input type date?

Sadly, support for date input seems to be completely absent in Safari on a Mac. The date input fields are presented as if they were text boxes, and the default value in the first field is not re-interpreted into a human readable format as with other browsers.

How do I restrict future dates in HTML5 input type date?

jQuery code getFullYear(); if(month < 10) month = '0' + month. toString(); if(day < 10) day = '0' + day. toString(); var maxDate = year + '-' + month + '-' + day; $('#txtDate'). attr('max', maxDate); });

How can set input type date in mm/dd/yyyy format using HTML?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.


1 Answers

Safari on iOS does not support the attributes max and min for input="date".

You could use a JavaScript datapicker like Pikaday for this. See demo below:

var today = new Date();
var lastMonth = new Date().getMonth() - 1;

var picker = new Pikaday({
  field: document.getElementById('datepicker'),
  maxDate: today,  // maximum/latest date set to today
  // demo only
  position: 'top left',
  reposition: false
});
<!-- Pikaday Library -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/pikaday/css/pikaday.css">
<script src="https://cdn.jsdelivr.net/npm/pikaday/pikaday.js"></script>

<!-- Datepicker Input -->
<label for="datepicker">Date</label>
<input type="text" id="datepicker">

For more info, please refer to the documentation on GitHub.

like image 108
edmundo Avatar answered Nov 02 '22 23:11

edmundo