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.
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
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-
.Closing this ticket as the issue is not our bug.