ipad web application: How do I prevent the keyboard from popping up on jquery datepicker

Viewed 38699

I have a form with an date field with a jquery datepicker attached to it.

When I select the date field the datepicker pops up but then the iPad keyboard slides into view and obscures the datepicker.

How do I prevent the keyboard from popping up in this situation?

11 Answers

I used a combination of CDeutsch and Rob's answers to disable the input field when the user clicks the calendar and then enable the field after the date picker closes as follows:

$(".date").datepicker({
    showOn: "button",
    onClose: function(dateText, inst) { $(this).attr("disabled", false); },
    beforeShow: function(dateText, inst) { $(this).attr("disabled", true); },
    buttonImage: "/images/calendar.png",
    buttonImageOnly: true
});

The benefit is that this allows the user to edit the date manually by clicking in the input field which brings up the iPad's keyboard or use the date picker by clicking on the date button.

Again thanks for all of the great input on this problem, I was stuck on this same issue until reading the above posts.

I have used this code and it works great... ".hasDatepicker" class is for my input that hold the date picker

<script type="text/javascript">

jQuery( document ).ready(function() {

var ybdDatePick = jQuery( ".hasDatepicker" );

    jQuery(function() {
       ybdDatePick.datepicker({ }).attr('readonly','readonly');

       ybdDatePick.on('focus',function() {
            jQuery(this).trigger('blur');
             this.datepicker({ }).attr('readonly','readonly');

          }
        );

});
});

I believe the better way to do this in modern browsers is to use inputmode="none". Here's the HTML code:

<input type="text" ... inputmode="none" />

At least on Android Chrome this is allowing my datepicker (obviously separately initialized via jQuery) to come up on my phone and the soft keyboard does not come up.

This prevents the issues that are possible with making the field readonly (not being able to clear the value, etc)

Related