go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.06k stars 1.29k forks source link

Expand `skip` to have the same other operators as `requred` and `excluded` #1245

Open deefdragon opened 3 months ago

deefdragon commented 3 months ago

Package version eg. v9, v10: v10.19.0

Issue, Question or Enhancement:

I currently have several options that are only relevant under select circumstances, the largest example of which is when certain fields don't matter (and thus their validation can be ignored) unless another field exists and or is set to a specific value.

With excluded_foo I could manage most cases if I could force the values to be empty, but unfortunately that is not something I edit or adjust in several cases. (most of these are dropdowns with non-empty default that are otherwise hidden on the form until some other value is set)

I am currently operating by skipping those validations in tags and writing a custom struct level validator that basically does the same thing. This is quite repetitive however.

It would also just make sense to have required, skip, and exclude all contain the same modifiers.

As an aside, the exclude_foo tags do not currently have docs for the modifiers other than if and unless. Adding these would be a good time to update the docs for the whole lot.

deefdragon commented 3 months ago

As a side note, I am willing to do the work on this if its considered worth it, I just need to get some approvals at work to contribute, which may take a week or two.

zemzale commented 3 months ago

I don't see a problem with this being added so feel free to open a PR. it might take a while for it to be reviewed and such, but it as long as it contains test cases it shouldn't be a problem.