thyrlian/AwesomeValidation

Focus runs away ... :(

rnitame opened this issue · 11 comments

https://gyazo.com/c41f51d2253ea5dbef0dcdb0d290c252

        val validation = AwesomeValidation(ValidationStyle.TEXT_INPUT_LAYOUT)
        validation.addValidation(
                address_edittext_layout,
                Patterns.EMAIL_ADDRESS,
                getString(R.string.incorrect_input_type)
        )
        val passwordRegex = "(?=.*[a-zA-Z])(?=.*[\\d]).{8,}"
        validation.addValidation(
                password_edittext_layout,
                passwordRegex,
                getString(R.string.incorrect_password)
        )

validation.validate() is fired on TextWatcher#afterTextChanged
Is there a solution?

If the validation succeeds the focus moves ... ? 🤔

Hi @rnitame, thanks for reporting the issue (I like the recorded video, shows clearly the problem).

But sorry that this is actually by design: in the library code, I force to set the focus to the first invalid field, so that the user could start to re-type right from there.

And if the validation is successful, then no change of focus.

oh... I see!
I cover with development :)

Cool, hope it's not annoying to you. Have fun with your project 👍

Thanks! This issue will close :)

I honestly think this should be up to the developer and the business rules of the application. If you can't validate as you type because the focus runs away, people are going to get confused because there will still be error messages until they try hit submit.

@lordplagus02 I agree with you, this should leave the decision to developer. I'll try to change the API design in the future, make the "requestFocus for the first failed field" as a boolean option in the initialization method param. How does that sound?

Woops only saw this now. That sounds like a good idea. I have a feeling most people will choose true, so perhaps this should be made default behaviour, allowing us to turn it off with false?

Yes.

Implemented by commit.

And mentioned usage in README:

// by default, it automatically sets focus to the first failed input field after validation is triggered
// you can disable this behavior by
AwesomeValidation.disableAutoFocusOnFirstFailure();

Awesome, I'll try it out ASAP.