[英]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.我还有 Optional/Required 字段以及 Regex 验证。 I have implemented Android Data binding using MVVM and hence I can now not use saripar .我已经使用 MVVM 实现了 Android 数据绑定,因此我现在不能使用saripar 。
I tried Kubwa but i can not use duplicate annotations there.我试过Kubwa,但我不能在那里使用重复的注释。 I have also had a look at android-binding ,but I couldn't implement the library and also they don't support it anymore.我也看过android-binding ,但我无法实现该库,而且他们不再支持它。 Let me know if anyone can suggest better approach.如果有人可以建议更好的方法,请告诉我。
if by "duplicate annotations" you mean multiple of the same type (2 or more @Email
validations) - then Kubwa will work.如果“重复注释”是指多个相同类型(2 个或更多@Email
验证) - 那么 Kubwa 将起作用。 All the annotations have a .List
sub annotation for such situations:对于这种情况,所有注释都有一个.List
子注释:
@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 :)免责声明 - Kubwa 是我的图书馆 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.