xrnd
xrnd

Reputation: 1342

How to validate form ViewModel with MVVM Data binding in Android?

I am trying to validate a form with mixed data type inputs from user. I also have Optional/Required field along with Regex validations. I have implemented Android Data binding using MVVM and hence I can now not use saripar.

I tried Kubwa but i can not use duplicate annotations there. I have also had a look at android-binding,but I couldn't implement the library and also they don't support it anymore. Let me know if anyone can suggest better approach.

Upvotes: 3

Views: 5136

Answers (1)

Boots
Boots

Reputation: 224

if by "duplicate annotations" you mean multiple of the same type (2 or more @Email validations) - then Kubwa will work. All the annotations have a .List sub annotation for such situations:

@NotNull.List({
    @NotNull(name = "streetError", errorMessage = R.string.streetError),
    @NotNull(name = "cityError", errorMessage = R.string.cityError),
    @NotNull(name = "countryError", errorMessage = R.string.countryError)
})

Disclaimer - Kubwa is my library :)

Upvotes: 2

Related Questions