KValidation icon indicating copy to clipboard operation
KValidation copied to clipboard

Enhancement: Add propertyName to ValidationError

Open RikuVan opened this issue 6 years ago • 2 comments

Presently the property name is added to the debugMessage. It would be useful to have the propertyName in the ValidationError. I am sending a list of errors to a client that maps them to inputs with the same name. I need to slice the property name out of the message, e.g. "planName: name must be at least 3 characters long".

RikuVan avatar Aug 22 '19 12:08 RikuVan

Thanks, will add in the next version.

deva666 avatar Aug 24 '19 07:08 deva666

Do you mean changing the error message from : Length validator, expected text length between: 0 - 6, received value: Patrick, property name: name to name: Length validator, expected text length between: 0 - 6, received value: Patrick ?

The message was generated using the following code (Inspired from LengthValidatorTests):

validator.forProperty { t -> t.name }
                .length(6)
                .onError()
                .propertyName("name")

testObject.name = "Patrick"
result = validator.validate()

(I'm asking the quetion, coz, I'm planing to make a PR for this issue)

oussamabadr avatar Nov 14 '20 19:11 oussamabadr