Skip to content
Discussion options

You must be logged in to vote

Yes you can do that through the pick method. see the docs: https://zog.dev/reference#complex-types

You would just do

formWithOnlyNameSchema:= formSchema.Pick("name")
formWithOnlyNameSchema.Validate(&form) // will only check the name field and ignore all the rest (i.e keep them as is)

edit: this is not very well documented in the docs. Probably should add a section on composability of schemas.

edit2: You can also do what you are doing and avoid code duplication by just having a local private global that has that specific schema like I mentioned in my first comment:

type SignupForm struct {
   Name string
}
var signupFormNameSchema = z.String().
		Required(z.Message("Name is required")).
		Max

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ycharron
Comment options

@Oudwins
Comment options

Answer selected by ycharron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants