Skip to content

Conversation

@weberamaral
Copy link

In all browsers in android devices the keyboard cursor is in the wrong position in fields that have
a mask

closes #32 #58 #127

In all browsers in android devices the keyboard cursor is in the wrong position in fields that have
a mask

closes candreoliveira#32 candreoliveira#58 candreoliveira#127
@mKurrels
Copy link

mKurrels commented May 7, 2017

This would be great! Thanks weberamaral! (Can we get this merged?)

@weberamaral
Copy link
Author

Hey @mKurrels how are you? Hope all is well.
Yes. You can get this merge.

@mKurrels
Copy link

@weberamaral
Oh, sorry, I don't have write access. I can't merge this. I was asking for someone that does have write access to merge.

vocjunior added a commit to izapbrasil/ngMask that referenced this pull request May 22, 2017
Implemented according with pull request candreoliveira#136 on oficial repository requested by https://github.com/weberamaral
@fredlemieux
Copy link

fredlemieux commented Aug 29, 2017

This solution works when testing in the emulator (Nexus 6P) but not when testing on these two devices: Samsung S7 and Huawei honor 9.

@julitroalves
Copy link

julitroalves commented Jan 23, 2018

Me too was with the same bug of wrong caret position. But after aplied the pull request of @weberamaral the problem was solved in my device. But in another device (another android version) testing I noticed that the problem continue. To solve this I added the following code after 142 line:

if (value !== viewValueWithDivisors) {
	controller.$viewValue = angular.copy(viewValueWithDivisors);
	controller.$render();

	$timeout(function() {
	    setSelectionRange(viewValueWithDivisors.length);
	    $element[0].focus();
	    $element[0].setSelectionRange(viewValueWithDivisors.length, viewValueWithDivisors.length + 1);
	});
}

@ronysilvati
Copy link

@julitroalves this code work fine on my Android 4.4.4! Trying on Iphone now!

@fredlemieux
Copy link

@julitroalves Great solution, this works on my Samsung S7 with Android 7.0. Finally, we have a solution to this! Can we merge this into the master branch please?

@palmej2
Copy link

palmej2 commented Feb 17, 2018

I tested it out, and needed to take what he had, and wrap it around an adroid check because that change didn't work on iphone... This is what worked for me (there's more elegant ways to do it)?

              if (value !== viewValueWithDivisors) {
                  //ORIGINAL CODE FOR NGMASK
                  //controller.$setViewValue(angular.copy(viewValueWithDivisors), 'input');
                  //controller.$render();

                  //FIXING ANDROID/CHROME PROBLEMS WITH MASKING CAUSING THE CURSOR TO GO ON WRONG SPOT
                  //START..
                  var ua = navigator.userAgent.toLowerCase();
                  var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
                  if (isAndroid) {
                      controller.$viewValue = angular.copy(viewValueWithDivisors);
                      controller.$render();

                      $timeout(function () {
                          setSelectionRange(viewValueWithDivisors.length);
                          $element[0].focus();
                          $element[0].setSelectionRange(viewValueWithDivisors.length, viewValueWithDivisors.length + 1);
                      });
                  }
                  else {
                    controller.$setViewValue(angular.copy(viewValueWithDivisors), 'input');
                    controller.$render();
                  }
                  //END..
              }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong caret position

6 participants