garde icon indicating copy to clipboard operation
garde copied to clipboard

Output value together with validation error

Open jirutka opened this issue 2 years ago • 3 comments

When the value of a field doesn’t pass the validation rule, I’d like to print a string representation of the value. This is supported in the validator crate, but not in garde.

Do you have an idea of how this could be ideally done?

This could also be solved by #7.

jirutka avatar Aug 12 '23 17:08 jirutka

garde doesn't store or output the values anywhere for security reasons (validator#157).

I think https://github.com/jprochazk/garde/issues/7 would definitely be the right solution to this. I'll add more context into that issue, because I believe there are a few important pre-requisites.

jprochazk avatar Aug 12 '23 18:08 jprochazk

garde doesn't store or output the values anywhere for security reasons (validator#157).

This is only relevant for a small fraction of use cases and it can be easily handled by some attribute per field, e.g. #[garde(sensitive)].

jirutka avatar Sep 02 '23 18:09 jirutka

This is only relevant for a small fraction of use cases

I'm not sure about that. I'd prefer to not have my validation library leak secrets by default, and require me to think about what is sensitive and what isn't.

My endgame is for garde to be able to act as the single source of truth for validation in web apps for both server and client sides, and in that case, I don't need the value to be output as part of the error, I just need the error itself to render next to the form input that already contains the invalid value.

jprochazk avatar Sep 03 '23 12:09 jprochazk