jquery.ui.touch.punch.js script is preventing inpu

2019-03-09 21:27发布

It took me a little bit, but I figured out that I can't click on my inputs because of the touch.punch script I'm using to enable jquery UI drag functionality on touch devices. Anyone familiar with this script know why that might be? The form actually resides down the tree of the parent object. Does anyone know a way I can override or force through the selection? I'm going to try binding events that force focus to the input right now but maybe someone here has some insight?

9条回答
\"骚年 ilove
2楼-- · 2019-03-09 22:00

Jacob's answer worked with a slight modification—I found that using the click event resulted in inconsistent behavior on iPad, ios9 Safari. Sometimes I'd press once on a field and it would focus, other times I had to press three times. Changing click to touchstart solved the problem for me (I also used event delegation since my form was added dynamically):

$('form').on('touchstart', 'input,textarea',function(){
    $(this).focus();
});
查看更多
聊天终结者
3楼-- · 2019-03-09 22:04

JEditable + jQuery UI Sortable + jquery.ui.touch-punch

I have spent all day on this problem and I finally figured out the solution. The solution is very similar to kidwon's answer. However, I was using jeditable which dynamically creates input fields without class names. So I used this conditional statement instead of checking the class name:

//Check if element is an input or a textarea
if ($(touch.target).is("input") || $(touch.target).is("textarea")) {
  event.stopPropagation();
} else {
  event.preventDefault();
}

I think this is a better solution as it always uses the native functionality for any input or textarea fields.

查看更多
Fickle 薄情
4楼-- · 2019-03-09 22:04

Thanks to @Danwilliger and @jeremytripp for the solution. Being that this issue has been known for years and yet has still not been worked into touch-punch author's Git repo, I forked it with the solution added here:

https://github.com/copernicus365/jquery-ui-touch-punch/blob/master/jquery.ui.touch-punch.js

I would be quite happy for the author to incorporate those few lines of a change into the original library and make this one unneeded then, but if that never happens, it's nice to have a single source file to reference.

查看更多
登录 后发表回答