We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System (please complete the following information):
macOS
1.23.3
1.5.4
Describe the bug
Scenes does not detect slice type
To Reproduce
package main import ( "fmt" "github.com/gookit/validate" ) func main() { u := &UserForm{ Name: "inhere", Code: "asd", Test: 1, } v := validate.Struct(u, "add") v.StopOnError = false // v := validate.New(u) if v.Validate("add") { // validate ok // do something ... } else { fmt.Println(v.Errors) // all error messages } fmt.Println() fmt.Println() fmt.Println() fmt.Println() fmt.Println() fmt.Println() v = validate.Struct(u, "update") v.StopOnError = false // v := validate.New(u) if v.Validate("update") { // validate ok // do something ... } else { fmt.Println(v.Errors) // all error messages } } // UserForm struct type UserForm struct { Name string `validate:"required|min_len:7"` Code string `validate:"required|customValidator"` // ExtInfo nested struct ExtInfo struct { Homepage string `validate:"required"` CityName string } `validate:"required"` Tags []struct { Id string `validate:"required"` Name string `validate:"required"` Date string `validate:"required"` } `validate:"required"` Test int `validate:"required|greaterThan:1"` } // CustomValidator custom validator in the source struct. func (f UserForm) CustomValidator(val string) bool { res := len(val) == 4 return res } // ConfigValidation config the Validation // eg: // - define validate scenes func (f UserForm) ConfigValidation(v *validate.Validation) { v.WithScenes(validate.SValues{ "add": []string{"ExtInfo.Homepage", "Name", "Code"}, "update": []string{"ExtInfo.CityName", "Name", "Tags.Id", "Test"}, }) } // Messages you can custom validator error messages. func (f UserForm) Messages() map[string]string { return validate.MS{ "required": "oh! the {field} is required", "email": "email is invalid", "Name.required": "message for special field", "Age.int": "age must int", "Age.min": "age min value is 1", } } // Translates you can custom field translates. func (f UserForm) Translates() map[string]string { return validate.MS{ "Name": "User Name", "Email": "User Email", "ExtInfo.Homepage": "Home Page", } }
Expected behavior
When scene update is used Tags.Id from slice should be validated and show in errors but this does not happen. There is no way to declare this in docs
Screenshots
Additional context
I don't know but this seems to be more like a feature request than an issue 😃
The text was updated successfully, but these errors were encountered:
inhere
No branches or pull requests
System (please complete the following information):
macOS
1.23.3
1.5.4
Describe the bug
Scenes does not detect slice type
To Reproduce
Expected behavior
When scene update is used Tags.Id from slice should be validated and show in errors but this does not happen. There is no way to declare this in docs
Screenshots
Additional context
I don't know but this seems to be more like a feature request than an issue 😃
The text was updated successfully, but these errors were encountered: