thyrlian/AwesomeValidation

Override for TextInputLayout seems broken

Closed this issue · 3 comments

I am attempting to do something like the following, assuming _clientNameInputLayout has been initialized:
addValidation(_clientNameInputLayout, RegexTemplate.NOT_EMPTY, R.string.field_required)
but I'm getting this error:

cannot resolve method 'addValidation(TextInputLayout, String, int)'

However, if I do the following:
addValidation(_clientNameInputLayout, RegexTemplate.NOT_EMPTY, "This field is required")
the compiler is happy.
Surely my initial statement should be allowed? Or am I doing something stupid?

It's by design.

You can either pass the resource ID for both the field and error message, like this:

addValidation(R.id.clientName, RegexTemplate.NOT_EMPTY, R.string.field_required);

Or pass object for both the field and error message, like this:

addValidation(_clientNameInputLayout, RegexTemplate.NOT_EMPTY, "This field is required");

But unfortunately you can't not pass them in a mixed way like what you did at the first try.

What is the reasoning behind this design choice?

The reason is:

  • Either you have the context, then you could simply pass the resource id and string, the library code would get the resource on behalf of you.
  • Without knowing the context, you just pass the view object itself and the validation message string.

Thanks.