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

TextInput cursour not moving when we change text from JS #1196

Open
Dhvl-Golakiya opened this issue Jun 1, 2018 · 1 comment
Open

TextInput cursour not moving when we change text from JS #1196

Dhvl-Golakiya opened this issue Jun 1, 2018 · 1 comment
Projects

Comments

@Dhvl-Golakiya
Copy link

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:

<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>

@BeeWarloc
Copy link

BeeWarloc commented Jun 18, 2018

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?

@AndrewEQ AndrewEQ added this to To Do in Core Nov 1, 2018
@AndrewEQ AndrewEQ moved this from To Do to Investigate in Core Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Core
  
Investigate
Development

No branches or pull requests

2 participants