ryanb/nested_form — pull request #211 by taavo (2012-10-29 03:12:54+00:00)
Title: Append after_nested_form_callbacks inside form

Currently, nested_form's form_for helpers call the parent helper, and then when that's done, run the callbacks to generate the blueprints. This means you're calling fields_for _after_ closing out the original form_for, which means:

1. A file_field in your blueprint won't automatically upgrade the parent form to multipart. (Or, more accurately, it will automatically upgrade the parent form to multipart, but the parent form will already be rendered by then and it'll be too late to include that fact in the output.)

2. client_side_validations can't generate validators for the fields in your blueprint, because the blueprint isn't rendered until client_side_validations' form_for is complete.

This pull request resolves the above issues by moving the blueprint from just outside the form_for call (and `

` tag) to just inside the form_for call (and `

` tag).

Note that following bcardarella/client_side_validations#421, if we're able to get this resolved, nested_form and client_side_validations may (pending further testing) finally be able to work together out of the box. The only integration necessary is to enable validations on added fields like so:

```
$('form').on('nested:fieldAdded', function(event) {
$(event.target).find(':input').enableClientSideValidations();
});
```