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

MaterialEditText Focuses on Multiple Edittexts during validation error #375

Open
ReejeshPK opened this issue Nov 18, 2018 · 0 comments
Open

Comments

@ReejeshPK
Copy link

Lets say we have 3 Material Edittexts, For all I have kept empty validation. Now, if I enter some text in the first edit text and goto the next, there is no problem. But if I leave the first one empty, and go to the next one, the Edittext cursor shows on both of them and i could not edit or focus the first one, struck in the second one. This was the issue, then, on analyzing it. found that a method requestFocus() in the class MaterialEditText.java inside a function validate() was causing the problem, commented it out, and now it works fine:

   public boolean validate() {
        if (validators == null || validators.isEmpty()) {
            return true;
        }

        CharSequence text = getText();
        boolean isEmpty = text.length() == 0;

        boolean isValid = true;
        for (METValidator validator : validators) {
            //noinspection ConstantConditions
            isValid = isValid && validator.isValid(text, isEmpty);
            if (!isValid) {
                setError(validator.getErrorMessage());
//-------------------------------this line was causing the problem---------------------------------------
                //requestFocus();
                break;
            }
        }
        if (isValid) {
            setError(null);
        }

        postInvalidate();
        return isValid;
    }
@ReejeshPK ReejeshPK changed the title Edittext Focuses on Multiple Edittexts during validation error MaterialEditText Focuses on Multiple Edittexts during validation error Nov 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant