You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am setting Phone number format in Text Input. While setting phone number format, a cursor is not moving with text changes so when I type new characters, they are adding between the text, not at last.
Check code:
<App>
<JavaScript>
var Observable = require('FuseJS/Observable');
var mobileNumber = Observable("");
mobileNumber.onValueChanged(module, function (text) {
var number = mobileNumber.value.replace(/[^\d]/g, '');
if (number.length === 7 || number.length === 8) {
number = number.replace(/(\d{3})(\d+)/, "$1-$2");
} else if (number.length === 9) {
number = number.replace(/(\d{3})(\d{3})(\d{3})/, "$1-$2-$3");
} else if (number.length > 9) {
number = number.replace(/(\d{3})(\d{3})(\d+)/, "($1) $2-$3");
}
if (number === mobileNumber.value) {
return;
}
mobileNumber.value = number;
});
module.exports = {
mobileNumber:mobileNumber
}
</JavaScript>
The text was updated successfully, but these errors were encountered:
I tested this on macOS, and observed that the cursor moves forward one step for every key pressed. However, when the number has additional separator characters inserted in onValueChanged the cursor will stay at the same index, which is counted from the beginning of the string. I agree that will look wrong in this usecase, but in general I believe this behavior is correct.
What you want is probably to also update the cursor in onValueChanged appropriately. Unfortunately, from what I can see in the documentation, getting or setting the cursor of a TextInput is not currently possible.
To me this seems like a generally useful feature; if you're interested in making a PR I'm sure it would be appreciated. I believe the code in question is here somwhere.
I have no experience with that code though, so the help I can provide with this is limited.
Regarding this specific issue, I think the behavior from the perspective of fuselibs is correct, and that this issue can be closed. Unless the behavior is different on other platforms?
Hi,
I am setting Phone number format in Text Input. While setting phone number format, a cursor is not moving with text changes so when I type new characters, they are adding between the text, not at last.
Check code:
The text was updated successfully, but these errors were encountered: