Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

support for nested attributes with dynamic number of elements #213

Merged
merged 1 commit into from Apr 24, 2012

Conversation

Projects
None yet
4 participants
Contributor

pkmiec commented Nov 1, 2011

Rebased as one commit.

Since the validations for each nested attribute are the same, there is no need to have them repeated for each model. Instead, the validations can be specified once for all the nested attributes and then applied to fields at any index.

For example, given users that accepts nested attributes for emails, the form will contain the following fields,

user[email_attributes][0][email_address]
user[email_attributes][1][email_address]
user[email_attributes][2][email_address]
user[email_attributes][N][email_address]

we can specify validation for all email_address fields simply as,

user[email_attributes][][email_address]

This not only sends less data to the client but also works with dynamic forms (i.e. press + to add another email address field).

astjohn commented Dec 1, 2011

This is a great addition that works for my dynamic fields. Thanks!

Contributor

pkmiec commented Dec 1, 2011

Cool.

I'm not really sure what's holding up the pull request, though.

Contributor

bcardarella commented Dec 1, 2011

I've been busy and haven't had the time to review the pull request, sorry.

Contributor

pkmiec commented Dec 1, 2011

Thanks for the update.

Contributor

bcardarella commented Mar 29, 2012

@pkmiec I'm very sorry I let this go stale. Can you please rebase so I can merge?

Contributor

pkmiec commented Mar 31, 2012

@bcardarella rebased ... there are test failures but the same failures occur on master.

This sounds like what I need too. I'm using Cocoon to dynamically add nested fields and the validations aren't being performed. The validation is a custom, remote validation. Interestingly, even when I'm editing a pre-existing object with nested objects already added the validations still aren't being performed. However, if I try and set the same validation on a top-level attribute, the validation works perfectly.

I'm hoping this will solve my problem and maybe I'll just wait until there's an update before worrying about it.

@bcardarella bcardarella added a commit that referenced this pull request Apr 24, 2012

@bcardarella bcardarella Merge pull request #213 from pkmiec/nested_attributes
support for nested attributes with dynamic number of elements
291e4f7

@bcardarella bcardarella merged commit 291e4f7 into DavyJonesLocker:master Apr 24, 2012

Contributor

bcardarella commented Apr 24, 2012

Totally forgot about this, merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment