Questions tagged [nested-forms]

A form within another form, often in the ruby-on-rails environment.

This is a Rails gem for conveniently manage multiple nested models in a single form. It does so in an unobtrusive way through jQuery or Prototype.

This gem only works with Rails 3.

Nested forms are when a form is placed within another form, often in the environment.

As of HTML 5, the form element can't be nested. Check section 4.10.18, "Association of controls and forms" for more information.

The platform can also handle nested forms, like the example below:

<div class="form">
    <?php $this->renderPartial('_form', array('form'=>$form)); ?>
    <?php echo $form['user']; ?>
    <?php echo $form['profile']; ?>
    <?php echo $form['subformbuttons']; ?>
</div>

Check the section for general questions and details about forms.

1948 questions
493
votes
20 answers

Can you nest html forms?

Is it possible to nest html forms like this
so that both forms work? My friend is having problems with this, a part of the subForm works, while another part of it does not.
Levi
  • 11,104
  • 13
  • 40
  • 47
103
votes
3 answers

Rails nested form with has_many :through, how to edit attributes of join model?

How do you edit the attributes of a join model when using accepts_nested_attributes_for? I have 3 models: Topics and Articles joined by Linkers class Topic < ActiveRecord::Base has_many :linkers has_many :articles, :through => :linkers,…
Arcolye
  • 6,863
  • 4
  • 29
  • 26
48
votes
2 answers

Rails - Using form_for and fields_for, how do you access the sub-object while in the fields_for block?

In my first rails app I'm trying to use form_for and fields_for to create a nested object form. So far so good, but I can't figure out how to access the sub-object while in the fields_for block. I've pre-populated a field in the sub-object with data…
Don Leatham
  • 2,664
  • 4
  • 27
  • 41
41
votes
1 answer

Error in slick.js: "Uncaught TypeError: Cannot read property 'add' of null"

I used slick js for slider view of image. Here is my code.
<%= f.fields_for :images do |image_form| %> <%#= render 'images_fields', :f => image_form %>
<%= image_tag…
Pooja Mokariya
  • 1,556
  • 4
  • 17
  • 37
38
votes
2 answers

symfony2 multiple nested forms prototype

I want to include a collection type inside another collection type. It should look like this: Using just one collection works fine, but I need to edit the prototype of the outer form, so it renders the prototype of the inner form for each line. Any…
brpaz
  • 3,453
  • 9
  • 44
  • 70
27
votes
3 answers

Rails has_many :through nested form

I have just jumped into has_many :through association. I'm trying to implement the ability to save data for all 3 tables (Physician, Patient and association table) through a single form. My migrations: class CreatePhysicians <…
Wanderer
  • 614
  • 2
  • 18
  • 41
26
votes
2 answers

fields_for not rendering - rails 3

Finally moved to Rails 3 for a new project and already running into a rookie problem. Trying to do a simple nested form. 2 models: list and tasks List model class List < ActiveRecord::Base has_many :tasks, :dependent=>:destroy …
Ryan
  • 379
  • 1
  • 5
  • 11
25
votes
4 answers

Nested forms in rails - accessing attribute in has_many relation

I have a user and a profile model. One user can have many profiles. I need to access only one information from the profiles section (viz the phone number) in my user model during the user creation process. Hence I'm trying to get it done through…
Swamy g
  • 2,016
  • 4
  • 23
  • 35
24
votes
4 answers

How to add and remove nested model fields dynamically using Haml and Formtastic

We've all seen the brilliant complex forms railscast where Ryan Bates explains how to dynamically add or remove nested objects within the parent object form using Javascript. Has anyone got any ideas about how these methods need to be modified so as…
Jack Kinsella
  • 4,098
  • 2
  • 34
  • 52
22
votes
2 answers

Malformed Packet: Django admin nested form can't submit, connection was reset

I have a django nested admin form and below code is my admin.py file content: # -*- coding:utf-8 -*- from django.db.models import Q from django import forms from django.contrib.auth.admin import UserAdmin as AuthUserAdmin from django.contrib import…
M.javid
  • 5,373
  • 3
  • 36
  • 52
22
votes
7 answers

Rails: validate presence of parent_id in has_many association

I have a projects resource that has many tasks. I want to ensure that every task has a project_id by adding validates_presence_of :project_id to the tasks model. However, when creating a new project with tasks, the project_id won't be available…
deb
  • 11,136
  • 19
  • 62
  • 83
21
votes
4 answers

how to avoid saving empty records on a nested rails form

I'm using the nested_form gem for my AddressBook relation. When the user blanks out the value of an existing Addr, I want to delete that Addr rather than saving with a blank value class Person < ActiveRecord::Base has_many :addrs, dependent:…
Chris Beck
  • 1,750
  • 1
  • 17
  • 25
20
votes
3 answers

Use rails nested model to *create* outer object and simultaneously *edit* existing nested object?

Using Rails 2.3.8 Goal is to create a Blogger while simultaneously updating the nested User model (in case info has changed, etc.), OR create a brand new user if it doesn't exist yet. Model: class Blogger < ActiveRecord::Base belongs_to :user …
Jase
  • 543
  • 5
  • 12
19
votes
5 answers

validates_uniqueness_of in destroyed nested model rails

I have a Project model which accepts nested attributes for Task. class Project < ActiveRecord::Base has_many :tasks accepts_nested_attributes_for :tasks, :allow_destroy => :true end class Task < ActiveRecord::Base validates_uniqueness_of…
arun
  • 303
  • 2
  • 6
19
votes
4 answers

Alternative for accepts_nested_attributes_for - maybe virtus

I'm relatively new to rails and finally found the right way to use accepts_nested_attributes_for. However, there are some serious resources on the web who say that using accepts_nested_attributes_for is generally a bad practice (like this one). What…
speendo
  • 11,483
  • 19
  • 66
  • 100
1
2 3
99 100