How to turn off iPhone keypad for a specified input field on web page
Asked Answered
K

2

10

I am using a monthpicker input (similar to jQuery UI datepicker) for a credit card expiration field.

I need to suppress the iPhone keypad because it hides the month picker.

I have tried setting the field to readonly and it is not an acceptable solution - in Safari iOS 5.1 readonly fields are skipped over in keyboard navigation (prev/next buttons on the keypad). Blurring the field is also not acceptable because it triggers validation (we are also using jQuery validation).

Is there a way to turn off the iPhone keyboard on a single field without setting it readonly or blurring it?

Katti answered 21/3, 2012 at 20:10 Comment(0)
D
5

I haven't come across the way to hide keyboard. But have you thought alternate way of displaying "input". One option would be using <input type="month" /> which brings the native month picker in iOS5.

Second option would be styling eg. span element as input element (-webkit-appearance not working on iOS), and adding tabindex for the element. This could also work, although I'm not aware of the month picker you're using.

Third option - can't you prevent the validation process when blurring the field is triggered manually?

Dashtilut answered 22/3, 2012 at 10:30 Comment(2)
Nice! <input type="month"/> throws a better month picker up for iPhone. Opera 11.6 pops up a full date picker so I'll have to work around that somehow. This doesn't answer the question as asked but it looks like it solves the problem.Katti
So I did a crappy user agent check for iPhone and iPod, and set the type attribute to "month" if true and only loaded the monthpicker if false. Works great. I'll revisit with a screensize + ontouchstart instead of user agent check later. Thank you very much!Katti
P
2

I had a same Issue in Drupal, where the input fields will be appending dynamically, so i added some js, checking for Iphone/Ipad and added "readonly" property

var checkUserAgent = navigator.userAgent;
    if (checkUserAgent.match(/iPad/i) || checkUserAgent.match(/iPhone/i)) {
        var checkBabyId1 = $('#babys_due_date_id').length > 0;
        if (checkBabyId1 == true) {
            $('#babys_due_date_id').find('input').prop('readonly', true);
        }
    }
Particolored answered 26/5, 2015 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.