KValidation icon indicating copy to clipboard operation
KValidation copied to clipboard

Enhancement: allow users to extend PropertyValidatorBase.kt and create own Validators

Open RikuVan opened this issue 6 years ago • 2 comments

I am surprised I cannot create my own reusable Validators. Maybe there is some technical reason I am missing that this is kept internal? If not it would be really nice to create one's own.

RikuVan avatar Aug 22 '19 19:08 RikuVan

Yes, makes sense. Will add it in the next version. Thanks

EDIT: You know that PropertyValidator interface is public? You can create your own validator with that. PropertyValidatorBase is kept internal because this is the base case for built in validator classes that are exposed in RuleBuilder functions.

deva666 avatar Aug 24 '19 06:08 deva666

I just found out that com.markodevcic.kvalidation.RuleBuilder#mustBe and com.markodevcic.kvalidation.RuleBuilder#setValidator can be used to add a custom validator:

validator.forProperty { t -> t.name }.mustBe { name -> name != null }

or

validator.forProperty { t -> t.name }.setValidator(myValidator)

myValidator implements com.markodevcic.kvalidation.validators.PropertyValidator so you can also customize other methods as well.

oussamabadr avatar Nov 14 '20 19:11 oussamabadr