Skip to content

String array should replace the existing one #42

Open
@aight8

Description

@aight8

Example:

type Form struct {
   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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions