I use the android-saripaar library.
I can check all the EditText fields on the correctness of the entered data using validate(). If I fill the EditText on with a mistake in correct data, the error doesn't disappear as long as I again call a validate().
How can I check the validity after entering text only in a certain EditText and to remove a mistake from it?
Thanks.
You can use Saripaar's Mode.IMMEDIATE in combination with TextWatcher instances to accomplish what you are looking for.
@Order annotation one every view fields that have Saripaar annotations. This is required to use immediate validation mode. If you want to validate rules in a specific order, each saripaar annotation has a sequence attribute. The sequence attribute is optional, but very helpful if you want the rules to be validated in a specific sequence.
@Order(1)
@NotEmpty(sequence = 1)
@Email(seqence = 2)
private EditText mEmailEditText;
@Order(2)
@Password
private EditText mPasswordEditText;
Set the mode to immediate mValidator.setMode(Mode.IMMEDIATE)
Add TextWatchers / appropriate listeners to your widgets.
TextWatcher validationTextWatcher = new TextWatcher() {
@Override
void afterTextChanged(Editable s) {
mValidator.validate();
}
// Other methods to override ...
}
mEmailEditText.addTextChangedListener(validationTextWatcher);
mPasswordEditText.addTextChangedListener(validationTextWatcher);
ViewValidatedAction implementation that will automatically clear errors on EditText fields when it is valid. If your form uses alternate error display mechanism / widgets, you can clear them by specifying your own ViewValidatedAction instance.
mValidator.setViewValidatedAction(new ViewValidatedAction() {
@Override
void onAllRulesPassed(View view) {
// ... clear errors based on the view type
}
});
Disclosure: I'm the author of Saripaar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With