Issue description
Using the setSelection method on a textField causes a _*change*_ event to be fired (when the value has not been updated).
Steps to reproduce
To reproduce this issue with a textField variable, the following code snippet should work and show the issue in action, once the user focuses on a given field:
// within method setting up textField event listeners
textFieldVar.addEventListener("focus", $.handleTextFieldEvent);
// elsewhere
$.handleTextFieldEvent = function(e) {
Ti.API.info(e.type + " event fired");
if(e.type === "focus"){
Ti.API.info("set selection of text");
e.source.setSelection(0, 1);
}
};
This should lead to output like:
[INFO] focus event fired
[INFO] set selection of text
[INFO] change event fired
Within a code flow that uses an auto-advancing form (based on single values within textField elements with change events that trigger a move onto the _next_ textField element), this effectively causes the form to be cycled through, and prevents user input.
Hi guys - is there any update on this? The only workaround we currently have for this would sacrifice usability and functionality, which is highly undesirable.
Hello [~plancaster] We have looked at this today and were able to reproduce. The change that triggers this behavior was a workaround for a google bug and was implemented 1 year ago. See https://stackoverflow.com/questions/22933803/edittexts-selectall-does-not-select-the-text-instead-cursor-is-moved-to-posi/35527348#35527348 for the description of the issue and https://github.com/appcelerator/titanium_mobile/blame/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIText.java#L683 for the section of the SDK where it was implemented. Basically it does a replace, which would fire the change event. At this point I don't have a good workaround for you, but as soon as I have a fix we can get you a build to try. 6.2.0 is our next build, scheduled for the end of this month. I will work with support to see what other options are available and will get you that info through them. I will update this ticket should we find a workaround in the meantime. Expect an update early next week.
Verified the issue is reproducible.
Result:
Studio Ver: 4.9.1.201707200100 SDK Ver: 6.1.2.GA OS Ver: 10.12.3 Xcode Ver: Xcode 8.3.3 Appc NPM: 4.2.9 Appc CLI: 6.2.3 Ti CLI Ver: 5.0.14 Alloy Ver: 1.9.13 Node Ver: 6.10.1 Java Ver: 1.8.0_101 Devices: ⇨ google Nexus 5 --- Android 6.0.1
PR (master): https://github.com/appcelerator/titanium_mobile/pull/9281 PR (6.2.X): https://github.com/appcelerator/titanium_mobile/pull/9282
FR Passed for both branches. PR merged.