Ilhasoft / data-binding-validator

Android fields validation library based on data binding adapters.
Apache License 2.0
344 stars 53 forks source link

Ignore validation if view is gone or invisible #5

Open oliveiradev opened 7 years ago

nicbell commented 7 years ago

This would be great.

manandhar-aarya commented 6 years ago

Hi, This is an old issue but it might help others in the future.

In the rule, while checking for valid, you can check if the view is visible. If the view is invisible or gone, then return true.

Code sample for EmptyRule: @Override public boolean isValid(TextView view) { //if view is invisible or gone then always return valid boolean isHidden = !(view.getVisibility()== View.VISIBLE); return isHidden || !value || !TextUtils.isEmpty(view.getText()); }

or to apply to all rules, you can add to the isValid function of class Rule<ViewType extends View, ValueType> itself.

joneserick commented 5 years ago

@manandhar-aarya Can you submit a pull request with your solution?

manandhar-aarya commented 5 years ago

I just did. :)