Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25061] Android: Fixed bug where TextField/TextArea setSelection() wrongly triggers a "change" event. #9281

Merged
merged 6 commits into from Aug 8, 2017

Conversation

jquick-axway
Copy link
Contributor

JIRA: https://jira.appcelerator.org/browse/TIMOB-25061

Test:

  1. Create an app using the below code and run it on Android.
  2. Tap the "Move Cursor to Front" button.
  3. Verify the cursor is on the left side of the field.
  4. Verify that a "change" event toast message is NOT displayed.
  5. Tap the "Move Cursor to Back" button.
  6. Verify the cursor is at the end of the field.
  7. Verify that a "change" event toast message is NOT displayed.
  8. Tap the "Select First Character" button.
  9. Verify that the 1st character in the TextField is highlighted.
  10. Verify that a "change" event toast message is NOT displayed.
  11. Tap the "Select Last Character" button.
  12. Verify that the last character in the TextField is highlighted.
  13. Verify that a "change" event toast message is NOT displayed.

var window = Ti.UI.createWindow({ layout: "vertical" });
var textField = Ti.UI.createTextField(
{
	value: "Hello World!",
	width: "90%",
	top: "5%",
});
textField.addEventListener("change", function(e) {
	var message = "TextField 'change' event received.";
	Ti.API.info(message);
	if ((Ti.Platform.name === "android") || (Ti.Platform.name === "windows")) {
		var notification = Ti.UI.createNotification(
		{
			message: message,
			duration: Ti.UI.NOTIFICATION_DURATION_SHORT,
		}).show();
	}
});
window.add(textField);
var moveCursorToFrontButton = Ti.UI.createButton(
{
	title: "Move Cursor to Front",
});
moveCursorToFrontButton.addEventListener("click", function(e) {
	textField.setSelection(0, 0);
});
window.add(moveCursorToFrontButton);
var moveCursorToBackButton = Ti.UI.createButton(
{
	title: "Move Cursor to Back",
});
moveCursorToBackButton.addEventListener("click", function(e) {
	var length = textField.value.length;
	textField.setSelection(length, length);
});
window.add(moveCursorToBackButton);
var selectFirstCharacterButton = Ti.UI.createButton(
{
	title: "Select First Character",
});
selectFirstCharacterButton.addEventListener("click", function(e) {
	var lastIndex = (textField.value.length > 0) ? 1 : 0;
	textField.setSelection(0, lastIndex);
});
window.add(selectFirstCharacterButton);
var selectLastCharacterButton = Ti.UI.createButton(
{
	title: "Select Last Character",
});
selectLastCharacterButton.addEventListener("click", function(e) {
	var length = textField.value.length;
	var startIndex = (length > 0) ? (length - 1) : 0;
	textField.setSelection(startIndex, length);
});
window.add(selectLastCharacterButton);
var selectAllButton = Ti.UI.createButton(
{
	title: "Select All",
});
selectAllButton.addEventListener("click", function(e) {
	textField.setSelection(0, textField.value.length);
});
window.add(selectAllButton);
window.open();

…n() wrongly triggers a "change" event.

- Also fixed code tabbing issues in "TiUIText.java".
Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS
FT: PASS

👍

@lokeshchdhry
Copy link
Contributor

lokeshchdhry commented Aug 8, 2017

FR Passed.

change event is not wrongly triggered anymore with setSelection.

Studio Ver: 4.9.1.201707200100
SDK Ver: 7.0.0 local build
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
Emulator: Android 7.0.0

@lokeshchdhry lokeshchdhry merged commit 30fe97b into tidev:master Aug 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants