-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Add support for nested values #11
Comments
@markbates should we start thinking on adding support for https://github.com/monoculum/formam instead of schema ? |
That's where I'm leaning. What are your thoughts? |
I've been having this sort of trouble (with schema) trying to implement an array value passed by the view, i've not had the chance to play with formam and have not had the chance to send a PR to schema, but just google and they seem to be looking for this kind of feature: WDYT if we do some effort and attempt to add arrays and maps support into schema ? my only fear on moving into formam is that schema seems more mature. |
Here's the code that caused me to switch off of schema: import "github.com/markbates/pop/slices"
type Contact struct {
...
Interests slices.Map `json:"interests" db:"interests"`
...
} <h1>Contact</h1>
<%= form_for(contact, {action: "/contact", errors: errors}) { %>
...
<label>Please check the topics that are of interest for you.</label>
<div class="row">
<%= for (g) in groupBy(2, interests) { %>
<div class="col-md-6">
<%= for (i, n) in g { %>
<%= f.CheckboxTag("Interests", {name: "Interests["+n+"]", value: contact.Interests[n], label: n, checked: n}) %>
<% } %>
</div>
<% } %>
</div>
...
<% } %> I couldn't probably handle the map in the contact struct. In the database it is stored as JSON. Schema couldn't handle it all, formam had no problem doing it. I just needed to register a different binder for it: func init() {
buffalo.RegisterBinder("application/x-www-form-urlencoded", func(req *http.Request, i interface{}) error {
err := req.ParseForm()
if err != nil {
return errors.WithStack(err)
}
dec := formam.NewDecoder(&formam.DecoderOptions{TagName: "formam"})
if err := dec.Decode(req.Form, i); err != nil {
return errors.WithStack(err)
}
return nil
})
} |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment. Otherwise, this will be closed in 7 days. |
If a Person has a Company on it, it would be great to be able to create a "sub form" for the Company.
The text was updated successfully, but these errors were encountered: