How to use required_if
when checking if a field equals a string with spaces in it?
#1085
Unanswered
geoff-maddock
asked this question in
Q&A
Replies: 2 comments 1 reply
-
In this case, you have to use the Hex code of the space which is Stage *string
ChurnReason *string `validate:"required_if=stage Churn0x20Reason"` See the docs : https://pkg.go.dev/github.com/go-playground/validator/v10#hdr-Using_Validator_Tags |
Beta Was this translation helpful? Give feedback.
1 reply
-
I don't know all the magic behind validators, but as a workaround, you can create a custom validator like this:
and the output/result is :
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to use
required_if
to validate requiring a field if another field equals a specific string that has a space in it. However, I can't determine the correct format for the expression. Here are the examples I've tried and the results. In every caseChurn Reason
is nil:This succeeds, no validation error - there should be an error since Churn Reason is required and it is not provided.
This returns an error
Bad param number for required_if ChurnReason
This returns an error
Bad param number for required_if ChurnReason
Beta Was this translation helpful? Give feedback.
All reactions