Android : Saripaar Validation Library. Need to set error message from strings.xml
Asked Answered
S

1

6

I am using the the Saripaar validation library https://github.com/ragunathjawahar/android-saripaar to validate one of the forms. The library is pretty useful as it avoids a lot of boilerplate code for validating a form. However, the library uses annontations on widgets. Below is an example:

@Password(order = 1)
@TextRule(order = 2, minLength = 6, message = "Enter at least 6 characters.")
private EditText passwordEditText;

The order attribute is the one that specifies the order in which the validations are going to take place. Here is my problem: the message attribute takes a constant expression. I need to set this from string Resource file. So that error messages can be internationalized later. I have already tried below:

message = getResources().getString(R.string.err_msg)

But it doesnt seem to work as it needs compile time constants.

Can anyone help me with the same or guide me through a workaround?

Sr answered 10/2, 2013 at 20:56 Comment(0)
D
18

Use this syntax :

//private variable in the class declaration section
private EditText txtFirstName=null; 
@Required(order = 2,  messageResId  = R.string.err_required_field)

It's in the lib's documentation (and the lib itself is an excellent one).

Debbradebby answered 24/2, 2013 at 19:3 Comment(3)
Thanx a lot mate. Found it in documentation after you pointed out. Thanks againSr
@Sr Could you point me the link to this lib's documentation. I couldn't found anything related with documentation on his library github repo .Siena
The documentation in the Github repo is partial. there is not documentation on the messageResId option.Debbradebby

© 2022 - 2024 — McMap. All rights reserved.