Skip to content
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 attributes with dynamic number of elements #213

Merged
merged 1 commit into from Apr 24, 2012
Merged

support for nested attributes with dynamic number of elements #213

merged 1 commit into from Apr 24, 2012

Conversation

pkmiec
Copy link
Contributor

@pkmiec 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
Copy link

astjohn commented Dec 1, 2011

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

@pkmiec
Copy link
Contributor Author

pkmiec commented Dec 1, 2011

Cool.

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

@bcardarella
Copy link
Contributor

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

@pkmiec
Copy link
Contributor Author

pkmiec commented Dec 1, 2011

Thanks for the update.

@bcardarella
Copy link
Contributor

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

@pkmiec
Copy link
Contributor Author

pkmiec commented Mar 31, 2012

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

@kstevens715
Copy link

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 added a commit that referenced this pull request Apr 24, 2012
support for nested attributes with dynamic number of elements
@bcardarella bcardarella merged commit 291e4f7 into DavyJonesLocker:master Apr 24, 2012
@bcardarella
Copy link
Contributor

Totally forgot about this, merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants