سؤال

The iPad defaults to today when an input type="date" gets focus (due to next/previous buttons and I presume tab/shift-tab using bluetooth keyboard) e.g. test using http://jsbin.com/etovur/1 on an iPad.

Question: Is there a workaround that works on both the iPad and iPhone to make the date not default to today when just navigating through the field?

This is a UI problem when editing existing data, and using next/previous to navigate through the fields, because it changes a blank to today e.g. termination date field of an employee gets set to today, and the employee is sacked.

We only need a solution that works on iPad/iPhone, and beware that input type=date implementation between the two devices has significant differences. Desktop browsers don't matter because we use a non-native date control (precisely to avoid problems with variation in how date controls work and look, or whether they are provided). The issue happens on at least iPad with iOS5, and iPhone with iOS6.

هل كانت مفيدة؟

المحلول

Mostly working solution: see http://jsbin.com/etovur/5 - when the date input gets focus set the value to '' after a delay.

  setTimeout(function() {
    document.getElementById('adate').value = '';
  }, 0);

The biggest problem is that this workaround makes it hard for the user to pick today (the user must scroll away from today and back again to pick today). Since this is an effect of the IMHO flawed over-simplified UI of the datepicker on iOS, I don't think there can be any viable solution to my original question.

Some possibility of timing bugs (next then quickly next on slow iPad?).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top