validator icon indicating copy to clipboard operation
validator copied to clipboard

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

Open deefdragon opened this issue 10 months ago • 2 comments

  • [x] I have looked at the documentation here first?
  • [x] I have looked at the examples provided that may showcase my question here?

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 avatar Mar 31 '24 09:03 deefdragon

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.

deefdragon avatar Mar 31 '24 09:03 deefdragon

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.

zemzale avatar Apr 02 '24 14:04 zemzale