$modal + ngTouch input issues on iOS/Android
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
I'm also having this exact same issue.
I'm having the same problem. Any update about this issue?
Might be related to this issue: https://github.com/angular-ui/bootstrap/issues/2017
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();
}
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?
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.
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.
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.
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.
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.
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.
Fixed via #3044
HI, how can i get the latest fixed?
is it merged already to the master branch?
@liadlivnat This fix is included in master.
@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?
@chrisirhc I'd like to know how the fix is going. I'm sorry to bother you, but it is essential for our product.
@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 :(
Hi, is there any news regarding the re-merging of the fix?
Thanks a lot.
+1
This is a very annoying bug.
BTW: @jdhiro's fix worked for me!