bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

$modal + ngTouch input issues on iOS/Android

Open ijlind opened this issue 12 years ago • 25 comments

There is a weird issue with modal windows containing input fields on iOS and Android if ngTouch is used. For some reason, you can only focus on an input field with a long touch gesture. A regular touch gesture won't focus on the field (and thus won't open the virtual keyboard). On desktop browsers the issue does not exist but it also seems to work as it should on Mobile IE (WP8).

Here's a plunkr demonstrating the issue: http://plnkr.co/edit/X95ZBUd6FK2I2R14e3Lr?p=preview

ijlind avatar May 30 '14 11:05 ijlind

I'm also having this exact same issue.

pablocespedes avatar Jun 18 '14 20:06 pablocespedes

I'm having the same problem. Any update about this issue?

pedubreuil avatar Jul 02 '14 17:07 pedubreuil

Might be related to this issue: https://github.com/angular-ui/bootstrap/issues/2017

pedubreuil avatar Jul 04 '14 13:07 pedubreuil

I confirm, this seems to be a bug of ngTouch... See this input blur() done here on the event "touchend" : https://github.com/angular/angular.js/blob/master/src/ngTouch/directive/ngClick.js#L256 The only solution I found is to write:

<div class="modal-body" >
   <input type="text" ng-click="getFocus()" />
</div>

with

scope.getFocus(){
   .....find('input')[0].focus();
}

pedubreuil avatar Jul 04 '14 17:07 pedubreuil

I am having the same issue, monkey patching the library is not an option for me. Any other ways to focus from controller for example?

angi-s avatar Sep 01 '14 10:09 angi-s

Hello all,

The issue mainly boils down to the modal template having an ngClick directive on the modal window itself. I couldn't tell you why this is necessary. In the angular-foundation package, which shares almost exactly the same html for the modal template, the ng-click="close($event)" doesn't map to anything at all. It's scope holds no close property or function.

Essentially what's happening here is: 1.) you tap on an input inside of a modal (basically a div with an ng-click directive) 2.) the parent modal window's ngClick directive detects a touchstart event 3.) ngTouch records the coordinates at which the touchstart occurred so that it can clickbust the the resulting click event that will fire afterwards naturally. 4.) touchend fires and ngTouch reconciles the ending point of your touch with where it began and determines that if a click event fires in the same spot, it'll bust it. 5.) a click event fires on the x and y coordinates where you touched (the input) and ngTouch clickbusts this event since it isn't "allowed". Clickbusting involves e.preventDefault(), e.stopPropagation() and event.target.blur() as seen on https://github.com/angular/angular.js/blob/master/src/ngTouch/directive/ngClick.js#L161

Some have found that commenting line 161 will resolve this, but probably precludes other desired functionality that line was intended for. Obviously, modifying an angular package isn't ideal. In my case, we ended up removing the module altogether. This probably can also be alleviated by removing the ng-click directive from the modal window itself. Can anyone comment on why the modal window has an ng-click directive?

See this plunker for a distilled case of this issue. Make sure you "emulate touch screen" from the chrome (or other) dev tools.

jbielick avatar Sep 05 '14 15:09 jbielick

I discovered this issue today and found the solution that best worked for me was removing ng-click="close($event)" from the modal window template. The functionality that was lossed was that clicking outside the modal no longer closes the modal. This was an acceptable loss in my application so this was the stablest and easiest way to resolve the issue as ngTouch was essential for other features like our image crop box.

I wonder if there's a way though to have the ng-click event put on the template for the modal backdrop as that is visually what the user clicks.

sean-stanley avatar Nov 07 '14 04:11 sean-stanley

Excellent explanation and investigation, @jbielick .

From what I see here, the simplest way to resolve this is to bind the click event manually using $modalElm.on on the modal element in JavaScript instead of using ng-click in the template. That should solve this issue as the ngTouch module is only affecting the ngClick directive. PRs are welcome.

chrisirhc avatar Nov 07 '14 09:11 chrisirhc

I also found this problem and solved it removing ng-click directive from template and binding a click event in the modal-window directive code. Not sure if this could break some other stuff but tests are ok and my project seems to be working ok with this fix.

I've created PR #3044 in case you think it's a good solution.

jiniguez avatar Dec 03 '14 00:12 jiniguez

I'm not sure it solves the issue 100%, when i open the modal it did let me enter a text, but when i closed the modal and re-open it, the bug is there again.

liadlivnat avatar Dec 14 '14 14:12 liadlivnat

removing ng-touch from .modal solved the problem for me as well. You can't just move it to the backdrop, because the .modal covers entire viewport and .modal-backdrop is actualy behind .modal and can't be clicked.

I saw somewhere else people solved it by stopping event propagation on .modal-body but I didn't manage to make it work for me.

What is the event that busts the click called? I have zero experience with event propagation, can someone look into it? I guess this would help a lot of people.

tomasreichmann avatar Jan 08 '15 08:01 tomasreichmann

Fixed via #3044

karianna avatar Jan 08 '15 08:01 karianna

HI, how can i get the latest fixed?

is it merged already to the master branch?

liadlivnat avatar Jan 13 '15 15:01 liadlivnat

@liadlivnat This fix is included in master.

antoinepairet avatar Jan 13 '15 20:01 antoinepairet

@antoinepairet when i'm doing bower update angular-ui-bootstrap i get Version: 0.11.2 - 2014-09-26, how can i get this version?

liadlivnat avatar Jan 14 '15 06:01 liadlivnat

@chrisirhc I'd like to know how the fix is going. I'm sorry to bother you, but it is essential for our product.

memolog avatar Jun 24 '15 05:06 memolog

@chrisirhc see here https://github.com/angular-ui/bootstrap/pull/3044#issuecomment-102533597. The fix apparently was merged and then reverted due to "not following merging guidelines" and has been forgotten since :(

piotrd avatar Jul 02 '15 17:07 piotrd

Hi, is there any news regarding the re-merging of the fix?

Thanks a lot.

vdeturckheim avatar Jul 08 '15 15:07 vdeturckheim

+1

This is a very annoying bug.

adgoncal avatar Jul 08 '15 15:07 adgoncal

BTW: @jdhiro's fix worked for me!

vdeturckheim avatar Jul 08 '15 16:07 vdeturckheim