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
typeFormstruct {
Field []string`form:"field"`
}
form:=Form{ Field: []string{"value1", "value2"} }
// vals is contains 'field': "value3", "value4"_:=Decoder.Decode(&form, vals)
// form.Field contains now "value1", "value2", "value3", "value4".// Excepted was only "value3", "value4"
If I decode the HTTP post values to this struct, the Field property gets appended by the values in the post data instead of replaced.
The use case is the following:
I pre-fill the Form struct with data based on the DB entity. I use this struct also in the view template to render the values.
If I would fill the Form struct after the decoding, it will override all the decoded fields if I not check every single field.
My logical expectation of the form decoder is:
If the form field exists in the values, make sure the value match the decoded value (now it's appending string array, don't tested other kind of arrays/struct array)
If not just leave the field how it is (works)
The text was updated successfully, but these errors were encountered:
Hey @aight8 this was done on purpose so that the user had full control over the decoding process, I can see how it would be convenient for deeper nested structures to have this done automatically if desired though.
I can look into adding a decode option so that this behaviour can be configured via an option.
Example:
If I decode the HTTP post values to this struct, the Field property gets appended by the values in the post data instead of replaced.
The use case is the following:
I pre-fill the Form struct with data based on the DB entity. I use this struct also in the view template to render the values.
If I would fill the Form struct after the decoding, it will override all the decoded fields if I not check every single field.
My logical expectation of the form decoder is:
The text was updated successfully, but these errors were encountered: