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

ignored validation when view is invisible or gone #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

manandhar-aarya
Copy link

No description provided.

@joneserick
Copy link
Contributor

@manandhar-aarya thanks a lot for your contribution. It works as expected on singular validations but It doesn't when trying to use multiple validations.

@manandhar-aarya
Copy link
Author

@jonoID Can you explain what you mean by singular and multiple validations?
I tried using multiple validation rules (as validateEmpty, validateMinLength, validateMaxLength) in one view and it still seems to work as expected.

@joneserick
Copy link
Contributor

Oh, sorry for not being clear in my words. The fact is that there is nothing wrong with your solution. I found that the hidden view validation doesn't work by calling Validation's validate(List<ViewType> views) method.

public <ViewType extends View> boolean validate(List<ViewType> views) {
    List<View> viewWithValidations = getViewsWithValidation(views);
    return isAllViewsValid(viewWithValidations);
}

private boolean isAllViewsValid(List<View> viewWithValidations) {
    boolean allViewsValid = true;
    for (View viewWithValidation : viewWithValidations) {
        boolean viewValid = true;
        List<Rule> rules = (List) viewWithValidation.getTag(R.id.validator_rule);
        for (Rule rule : rules) {
            viewValid = viewValid && isRuleValid(rule);
            allViewsValid = allViewsValid && viewValid;
        }

        if(mode == FIELD_VALIDATION_MODE && !viewValid) {
            break;
        }
    }
    return allViewsValid;
}

But it only occurs when you by mistake includes a hidden view to be validated. In this case the hidden view should be included on the disabledViews list, so it will return true on the rule verification:

private boolean isRuleValid(Rule rule) {
    return disabledViews.contains(rule.getView()) || rule.validate();
}

The crazy thing is that it should work because if disabledViews list doesn't contain the respective view, the rule's validate() method should handle the visibility property. Maybe I'm missing something.

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

Successfully merging this pull request may close these issues.

2 participants