Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23611] Android: Set textfield value by coding will make cursor to the beginning of textfield

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionNot Our Bug
Resolution Date2016-11-17T00:19:09.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterShuo Liang
AssigneeEric Merriman
Created2016-07-02T02:37:30.000+0000
Updated2017-03-21T20:51:31.000+0000

Description

Reproduce Problem

1. Add following code to app.
var win = Ti.UI.createWindow({});
 
var view = Ti.UI.createView();

var tf = Ti.UI.createTextField({ 
	top: 50, 
	width: Ti.UI.FULL, 
	right: 20, 
	left: 20, 
	keyboardType: Ti.UI.KEYBOARD_DECIMAL_PAD, 
	maxLength: 12, 
	borderWidth: 1, 
	borderColor: "black", 
	suppressReturn: true, 
	bottom: 20, 
	height: Ti.UI.SIZE 
}); 


var btnchange = Ti.UI.createButton({ 
	title: "change" 
}); 

btnchange.addEventListener('click', function() { 
	tf.value = '213-33'; 
	tf.setSelection(tf.value.length, tf.value.length);
}); 

view.add(tf); 
view.add(btnchange); 
win.add(view); 

win.open();
2. Run the app in Android device. 3. Click change button

Expect Result

The value of textfield is set, and cursor is in the end of text

Actual Result

The cursor will be in the beginning of text

Note

Only happens for Android, iOS working well.

Comments

  1. Michael Gangolf 2016-11-06

    Just testing this on Android and I think the \- is the problem. Since the keyboardType is set to TYPE_NUMBER_FLAG_DECIMAL a \- is only allowed at the beginning of the TextField (https://developer.android.com/reference/android/text/InputType.html#TYPE_NUMBER_FLAG_SIGNED) since it changes the inputtype of the textfield. When you run the code you'll see that the fist 2 is missing and you'll get a index out of bounce error. If you remove the middle "-" the code runs fine and the cursor is at the end. So it might be usefull to add a check for real decimal values in setValue when the keyboard is set to DECIMAL on Android SDK: 6.0.0.v20161104064744
  2. Hans Knöchel 2016-11-06

    Thanks Michael, good catch! [~sliang] Can you apply those changes? Summarized, the problem is that you used non-decimal values in a text field that has a Ti.UI.KEYBOARD_DECIMAL_PAD and will therefore cause problems with the value. So either stick to a non-decimal keyboard or remove the -.
  3. Lee Morris 2017-03-21

    Closing this ticket as the issue is not our bug.

JSON Source