Skip to content

Support for nested arrays with structs #40

Description

@murrekatt

Thanks for the great work you've done with martini and its companions like binding! :)

Now to the issue...It seems that it isn't possible to have a nested array of some own structs (yes, I saw no tests for it either) like so:

type Foo struct {
  Bars []Bar
}

type Bar struct {
  A string `form:"a"`
  B string `form:"b"`
}

Binding Foo with the above will not work and it ignores the form fields a and b even if they are passed in. Removing the [] and just having a single copy works fine (as you also have in the tests).

Before I start sending a PR I'd like to see what makes sense to do here.

Does it make sense to have an array of structs? I think so. Imagine having a form with a dynamic part where one can add zero or more of some set of fields. It would make sense to have a struct to represent those, and bang!, we have this very problem.

How would that look like on the form side to start with? I see that an array of strings for instance just takes all fields with the name and sticks them into the array. The implication of this is that it's not possible to have different fields with the same name. Would the same principle be a good approach now as well?

I'd like to hear what you guys who have worked on this a longer time have to say. What do you think is a good way to support what I ask for or is it even something you think makes sense to support?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions