I am using input type=date to capture a date from user. Because we cannot have placeholder for input(type=date), I have done the following:
- created the input field with Type text with a placeholder
- in JS, on focus, changing the type to date
$("#datefield").on('focus', function() {
$("#datefield").attr('type', 'date');
})
In IOS, this is working perfectly fine and brings the native datepicker everytime I tap on the input field. But in android, it brings the native datepicker but I have to click twice. After debugging, I found on first, it goes through the focus event and change the type to date. On second click, it doesn't go through the event, but brings the native keyboard. After that as long as I stay on that page, because the type has been changed to date, it will bring the native datepicker on one click.
Am I handling it the right way? What am I doing wrong? Is there any better way of doing it?
P.S. I want to avoid plugins as long as I can. I am using, HTML, CSS, JS, Jquery