validator icon indicating copy to clipboard operation
validator copied to clipboard

support custom FieldLevel error message when use RegisterValidation

Open RelicOfTesla opened this issue 6 years ago • 3 comments

Package version eg. v8, v9:

v9

Issue, Question or Enhancement:

validator.StructLevel type, has method ReportError(....)

but, validator.FieldLevel type can't not support set some custom error message. that are only use const translation map or const string "Key: '%s' Error:Field validation for '%s' failed on the '%s' tag" . Can not relation with input value!

Code sample, to showcase or reproduce:


RelicOfTesla avatar Aug 22 '19 23:08 RelicOfTesla

Hey @RelicOfTesla yes I'm investigating different options that may make it easier for custom translations, however having said that all information should be available on the returned errors to create custom error messages in the meantime and the originally intended way to customize error messages.

deankarn avatar Aug 24 '19 17:08 deankarn

Yeah, definitely need Field level custom tag to return error rather than bool, to report better error message to user. Please consider of this sir.

kidlj avatar Nov 01 '19 11:11 kidlj

custom validation is for area where normal tags fail. Image scenario that during validation we connect to database and connection failed. We return false, but user has nothing wrong with the data. Or complex situation that check multiple field in one validator like variation to exclude_if error can be even on different field. Ability to reqister function (error) or (bool,error) will resolve this. Alternative solution need struct validation and complex crawling function to be able reach ReportError

tvojacek avatar Oct 03 '25 14:10 tvojacek