android-saripaar icon indicating copy to clipboard operation
android-saripaar copied to clipboard

Allow override default messages

Open m-radzikowski opened this issue 9 years ago • 2 comments

Adding multiple validated fields across multi-lang application requires many repetitions of

@NotEmpty(messageResId = R.string.error_empty)
private EditText firstnameView;
@NotEmpty(messageResId = R.string.error_empty)
private EditText lastnameView;
@NotEmpty(messageResId = R.string.error_empty)
private EditText addressView;
// and so on...

Without specifying messageResId Saripaar uses default message defined in annotation, in this case

public String message()     default "This field is required";

Maybe default messages could be moved into strings.xml and specified in annotation as, in this case:

public int messageResId()   default R.string.saripaar_msg_required;
public String message()     default "";

message would be used only if it wouldn't be empty, in other case resource specified by messageResId would be used.

And then, according to http://developer.android.com/tools/projects/index.html#considerations

Since the tools merge the resources of a library module with those of a dependent application module, a given resource ID might be defined in both modules. In this case, the tools select the resource from the application, or the library with highest priority, and discard the other resource. As you develop your applications, be aware that common resource IDs are likely to be defined in more than one project and will be merged, with the resource from the application or highest-priority library taking precedence.

So in app using Saripaar it could be possible to override default messages in own strings.xml file.

If this enhancement would be accepted I can try to develop it.

m-radzikowski avatar Jun 29 '15 16:06 m-radzikowski

@m-radzikowski This is a really interesting idea. If we adopt this, we have to switch from offering JARs to AARs. That is one thing, it would certainly break compatibility with users who are still using Eclipse. I have planned a couple of features for 2.1.0. Once I'm done with that, we can proceed with this idea.

So, post 2.1.0, we'll offer AARs and break compatibility with Eclipse. Users would have to switch to Android Studio & Gradle to use Saripaar 2.1.0+

ragunathjawahar avatar Aug 01 '15 04:08 ragunathjawahar

The 2.1.0 would have at least the following,

  • DSL for creating dynamic messages
  • @Or and @Optional Annotations

I think, it would be nice to have these features available for users who are still using Eclipse. After implementing these, we'll add this ability to override default messages. In fact, a DSL is required to implement this feature because the generated resource IDs are not final in a library project. And annotations can ONLY accept final variables for it's attributes.

ragunathjawahar avatar Aug 05 '15 14:08 ragunathjawahar