bootstrap-datepicker icon indicating copy to clipboard operation
bootstrap-datepicker copied to clipboard

Input disableTouchKeyboard

Open Glideh opened this issue 12 years ago • 13 comments

In input mode, shouldn't we have a disableTouchKeyboard option to prevent mobile keyboard to pop out when the input is focused ? Setting it readonly seems not a good idea for me as it suggests we can't change the value.

Glideh avatar Jan 17 '14 16:01 Glideh

This would definitely be useful, as the touch keyboard on most devices obscures half the page, which when you're working with a datepicker anyway means that the form becomes rather unwieldy.

Screenshot: https://f.cloud.github.com/assets/5637797/2217996/cafd628a-9a25-11e3-8887-5e12fb459335.png

CalamityJames avatar Feb 20 '14 11:02 CalamityJames

I'm not sure this is possible, outside of setting readonly on the input. If you have any reading on doing this from a webpage, feel free to link it, but some searching on my part turned up a lot of "nope, can't do that". I seem to recall that some mobile browsers had proprietary css for disabling the keyboard, but I can't find anything about that now.

readonly just means the user can't change the value -- the page (via js) can always change the value (even for disabled inputs!). I agree it's not a great solution, but it looks like the only solution we have right now.

eternicode avatar Mar 03 '14 01:03 eternicode

I use it with jonthornton/jquery-timepicker (look at the related option). I didn't check the implementation though.

Glideh avatar Mar 03 '14 07:03 Glideh

Also (I didn't see this option) maybe we should have an HTML5 date input fallback for browsers supporting it, but that's another issue

Glideh avatar Mar 03 '14 07:03 Glideh

Thanks for the example @Glideh, I've managed to include that in the scripts (adds the option disableTouchKeyboard with a default of false) and it seems to be working!

https://f.cloud.github.com/assets/5637797/2308633/86b99b94-a2c1-11e3-9739-2e3a7c8b8719.png

CalamityJames avatar Mar 03 '14 10:03 CalamityJames

Good catch, thanks for the PR.

(window.navigator.msMaxTouchPoints || 'ontouchstart' in document)

Seems indeed to be the key

Glideh avatar Mar 03 '14 11:03 Glideh

I'm still having an issue with this, it still pops up the keyboard on both the Samsung s4 mini and Sony Xperia Z3 (android 4.4.2 and 4.4.4 respectively). Pulling my hair out on this one..

MrSleeps avatar Jan 28 '15 23:01 MrSleeps

Confirmed re-occurring on my Galaxy S6 Edge too running Android 5.0.2 on Chrome and stock browser.

I don't have an iPhone to test on though I'm afraid.

Sorry chaps. Will try and find some time to dig back through the code and see what's different in newer rendering engines (maybe the msMaxTouchPoints or ontouchstart variables are not passed any more).

CalamityJames avatar Apr 29 '15 11:04 CalamityJames

Can you try this? I don't have access to Android devices, but this code snippet is from a rather great library, interact.js, so it should be actual.

var supportsTouch = (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch);

razvanphp avatar Jun 23 '15 00:06 razvanphp

@razvanphp can you create a jsfiddle to test the piece of code? I have access to a fex android and ios devices so i'm able to test the snippet on different types of devices!

acrobat avatar Jun 23 '15 06:06 acrobat

+1

v1.5.0 HTC One with Android 5.0.2 Chrome 47.0

maximelebreton avatar Feb 08 '16 12:02 maximelebreton

i dont think that msMaxTouchPoints or ontouchstart variables are the problem, because i made this workaround based on the same variables and it works.

i've just added a little trick to improve accessibility. (but of course this is not perfect)

var isDatepickerVisible = false;

$('.datepicker').datepicker({
    disableTouchKeyboard: false

  }).on('show', function(e) {
    /**
     * hack to disable touch keyboard with blur() method,
     * but only if the datepicker is not visible (to minimize accessibility problems)
     * so with a second click, the keyboard appears
     */
    if ((window.navigator.msMaxTouchPoints || 'ontouchstart' in document)) {
      if (!isDatepickerVisible) {
        $('input', $(this))[0].blur();
      }
    }
    isDatepickerVisible = true;

  }).on('hide', function(e) {
    isDatepickerVisible = false;
  });

tested on: HTC One / Android 5.0.2 / Chrome 47.0 iPad 3 / iOS 9.0.2 / Chrome & Safari

maximelebreton avatar Feb 08 '16 16:02 maximelebreton

@maximelebreton care to create a PR with a fix?

acrobat avatar Feb 08 '16 18:02 acrobat