Open srinnix1395 opened 6 years ago
Hi, @srinnix1395 I have the same problem. Have you solved this problem?
I have a solution and it works fine for me.
First of all, you need to set a sequence. In my case first message to show it's NotEmpty
@NotEmpty(sequence = 1, messageResId = R.string.error_blank_email)
@Email(sequence = 2, messageResId = R.string.error_invalid_email)
@BindView(R.id.et_email)
protected TextInputEditText emailInput;
After that, you need to overwrite the default method getCollatedErrorMessage(Context context) to:
public static String getCollatedErrorMessage(final Context context, List<Rule> failedRules) {
return failedRules.get(0).getMessage(context);
}
The last step is to call a message in onValidationFailed() method :
@Override
public void onValidationFailed(List<ValidationError> errors) {
for (ValidationError error : errors) {
View view = error.getView();
// String message = error.getCollatedErrorMessage(this);
**String message = getCollatedErrorMessage(this, error.getFailedRules());**
if (view instanceof EditText) {
...
} else {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
}
}
I am using 3 validtion on one EditText. When the validation is completed, I use
getCollatedErrorMessage
function, but that function return 3 error (3 error appended). I want the function can get one error. And the order of validation will be handled in an order, eg: NotEmpty, Length, Email, if one condition failed, I want get the corresponding error. How can I do?