validator icon indicating copy to clipboard operation
validator copied to clipboard

how to support required_if that Field1 value is one of some value

Open jobsLee-lcj opened this issue 5 months ago • 1 comments

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

Package version eg. v9, v10:

v10

Issue, Question or Enhancement:

I know that required_if support Field1 is equal to the parameter given like:

// require the field if the Field1 is equal to the parameter given: Usage: required_if=Field1 foobar

but,what I wanted is required_if=Field1 foobar|test1|test2 when Field1 is a enum string and Field1 value is one of foobar,test1,test2.

Code sample, to showcase or reproduce:

type UpdateIAMUserRequest struct {
	CloudProvider  CloudProvider `json:"cloudProvider" binding:"required,oneof=AlibabaCloud AWS HuaweiCloud QiniuCloud BaiduCloud Volcengine TencentCloud RedCloud"`
	UID            string        `json:"uid" binding:"required"`
	Name           string        `json:"name" binding:"required_if=CloudProvider AWS|BaiduCloud|Volcengine|TencentCloud"`
}

jobsLee-lcj avatar Sep 05 '24 06:09 jobsLee-lcj