Order is not working w.r.t the required_with and len tag
- [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
Issue, Question or Enhancement:
Question
Code sample, to showcase or reproduce:
package main
import "fmt"
import "github.com/go-playground/validator/v10"
type NomineeChangeInfo struct {
Name string `json:"name" validate:"required_with=Dob,max=40"`
Dob string `json:"dob" validate:"required_with=Name,len=10"`
}
func main() {
fmt.Println("Hello, Go in CodeSandbox!")
validate := validator.New()
// Define a form with Email provided but Username missing
formWithEmail := NomineeChangeInfo{
Dob:"",
Name:"",
}
// Validate the form
err := validate.Struct(formWithEmail)
if err != nil {
fmt.Println("Validation error:", err)
} else {
fmt.Println("Validation successful")
}
}
so in the above example for DOB we are getting the error as Error:Field validation for 'Dob' failed on the 'len' tag but there should have been no errro, if required_with is already in false state.
required_if, required_unless,required_with,required_with_all,required_without,required_without_all,excluded_if,excluded_unless,excluded_with,excluded_with_all,excluded_without,excluded_without_all,skip_unless
if they meet the criteria for skipping, should skip all subsequent validation。
@deankarn Hello, what do you think of this suggestion
Yes that’s the way I expected those tags to work also, but they aren’t documented that way.
gonna have to double check if it ever behaved that way before. Will try to take a look this week, hopefully can find time.
PromotionType string `json:"promotion_type" binding:"required,oneof= a b c"`
ApplicablePhase []ApplicablePhaseItem `json:"applicable_phase" binding:"required_if=PromotionType a,dive,len=4"`
@deankarn In this example, len tag not working when required_if meets condition
PromotionType string `json:"promotion_type" binding:"required,oneof= a b c"` ApplicablePhase []ApplicablePhaseItem `json:"applicable_phase" binding:"required_if=PromotionType a,dive,len=4"`@deankarn In this example, len tag not working when required_if meets condition
it's not conform to the logic of this issues
Any news?
@deankarn any comments would be welcome. Is it even feasible for this to work the way some of us would like?