You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have a user struct, populated via a database query that includes a LastName field already populated
We have a user update HTML form which posts the updates.
Issue
When LastName, or other fields, are set to blank in the HTML input the form posts the following:
this is correct as you can see LastName has no value; however after running schema decoder like so:
// user originally grabbed from DB in middleware and set on context ( using gorilla contaxt )user:=context.Get(r, "user").(*User)
iferr=schemaDecoder.Decode(user, r.MultipartForm.Value); err!=nil {
log.Println(err.Error())
http.Error(w, "Invalid Request", http.StatusBadRequest)
return
}
fmt.Println(user.LastName) // outputs Bloggs, the fields original value
LastName was not set to blank and still retains it's original value.
My specific problem
the user struct is validated after schema decoder runs and in this situation validation should report an error, however it all passes, user gets saved to the database and user is notified that the user saved successfully.
Notes
This is not the same issue as #17 as I don't want to zero out fields not posted.
The text was updated successfully, but these errors were encountered:
Situation
Have a user struct, populated via a database query that includes a LastName field already populated
We have a user update HTML form which posts the updates.
Issue
When LastName, or other fields, are set to blank in the HTML input the form posts the following:
map[IsActive:[true] FirstName:[Joey] LastName:[] PreferredFirstName:[Joey] Username:[joeybloggs]]
this is correct as you can see LastName has no value; however after running schema decoder like so:
LastName was not set to blank and still retains it's original value.
My specific problem
the user struct is validated after schema decoder runs and in this situation validation should report an error, however it all passes, user gets saved to the database and user is notified that the user saved successfully.
Notes
This is not the same issue as #17 as I don't want to zero out fields not posted.
The text was updated successfully, but these errors were encountered: