-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for nested arrays with structs #40
Comments
The lack of grouping/hierarchy of the fields on the form side is a problem and it would be beneficial to have something that models it as the natural way one arranges the struct(s) like e.g. JSON would do it or a nested key-value store. This would give a namespace that allows for same named fields in different structs. Let's look at an example. Say we have a
This could be as a JSON message like so
What about having the form use names in some way that models this too? |
Here's for reference how Rails does it. |
hi, any progress on this issue? |
(Not from me) |
I have a ready-made code that does from this:
This: PersonSlice{
Name:"John Doe",
PhoneNumbers: []PhoneNumber{
{CountryCode:"41", Number:"1234567890"},
{CountryCode:"1", Number:"555-1234"},
},
Addresses:[]Address{
{Street:"Calm street 1", City:"Zürich", Country:"Switzerland"},
{Street:"Kleinstraße 2", City:"Berlin", Country:"Germany"},
{Street:"Le Grand Rue 10", City:"Toulon", Country:"France"},
},
}, But I uses a non-standard Parameter Naming Conventions (not like in php or Rails) |
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:
Binding
Foo
with the above will not work and it ignores the form fieldsa
andb
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!
The text was updated successfully, but these errors were encountered: