Last active
July 24, 2018 18:18
-
-
Save antonyalkmim/0e66f4ae25217a1ce0dca0b245f494e3 to your computer and use it in GitHub Desktop.
Textfield masks on Appcelerator Titanium Android. Solution to stop infinite loops when changing value of a textfield inside your change listener on Appcelerator Titanium Android.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var changed = false; | |
$.texfield.addEventListener("change", function(e){ | |
if(OS_IOS || (OS_ANDROID && !changed)){ | |
e.source.value = "My Mask"; //Masker.toPatter(); | |
} | |
changed = !changed; | |
//Set cursor at the end | |
var len = event.source.value.length; | |
$.textfield.setSelection(len, len); | |
}); |
Hi deckameron,
This worked very well for me.
Thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi antonyalkmim,
I have tried your approach on Android and iOS, but I could get it to work only on iOS. On Android, every time you "setSelection" it counts as new "change" event, therefore it goes into the infinite loop. The only way I could get it to work was this below.
I know it is not the most beautiful and well coded solution but it worked. :-)