Questions tagged [cocoon-gem]

Cocoon makes creating dynamic nested forms using jQuery easy. It works with formtastic, simple_form, and default forms.

Useful links for Cocoon

499 questions
21
votes
1 answer

Rails - Dynamically build deeply nested objects (Cocoon / nested_form)

I currently have a complex form with deep nesting, and I am using the Cocoon gem to dynamically add sections as required (e.g. if a user wants to add another vehicle to the sale form). Code looks like this: <%= sale.fields_for :sale_vehicles do…
Harry
  • 4,660
  • 7
  • 37
  • 65
15
votes
4 answers

How to use cocoon gem in Rails 6

Have been using cocoon gem for nested forms in rails 4 & rails 5 apps. Currently, I was updating one of the rails 5.2 app (which is using cocoon gem) to rails 6. As rails 6 is using webpacker, so I tired to require cocoon javascript in…
Sikandar Tariq
  • 1,296
  • 1
  • 13
  • 29
14
votes
1 answer

Rails Cocoon Gem: Undefined Method 'new_record?' on link_to_remove_association with Wicked

I have been trying to get some code figured out. I have a form I am trying to use the Wicked and Cocoon gem. Everything works, including the link_to_add_association function. I am rendering a partial for the associated form fields just like Cocoon…
jah.humes
  • 565
  • 4
  • 9
13
votes
1 answer

nested_form/cocoon: is it okay to use table rows for nested fields?

I normally don't use tables for forms, but when having a nested form (when using nested_form or cocoon gem), is it okay then to put each set of form elements inside a table row? To me, this seems pretty intuitive: every row in the table represents…
Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152
10
votes
2 answers

link_to_remove_association is not removing?

How can we fix the nested_attribute: _result_fields.html.erb so that when a user clicks "Delete" that it actually deletes it? Whereas now clicking it does nothing. <%= f.text_field :result_value, class: 'form-control', placeholder: 'Enter Result'…
AnthonyGalli.com
  • 2,796
  • 5
  • 31
  • 80
8
votes
1 answer

Cocoon data-association-insertion-node with a function

According https://github.com/nathanvda/cocoon#link_to_add_association you should be able to pass a function to data-association-insertion-node I have tried this: <%= link_to_add_association 'Add Timeslot', f, :timeslots, :data =>…
DrevanTonder
  • 726
  • 2
  • 12
  • 32
8
votes
1 answer

_destroy isn't working in Coocon gem with Rails 4

I have the same issue as this one But that solution didn't help me. Here are my strong params: def request_params params.require(:request).permit(:name, :address, :phone, :mobile, :type, :filled_cartridges_attributes =>…
yerassyl
  • 2,958
  • 6
  • 42
  • 68
7
votes
3 answers

Rails 3 Cocoon link_to_add_association Renders Partial Twice

My partial gets rendered twice instead of only once, as expected. Any thoughts? Here's my Person view <%= simple_nested_form_for(@person) do |f| %> <%= f.error_notification %>
<%= f.input :name %>

Records…

roobeedeedada
  • 511
  • 4
  • 11
7
votes
2 answers

Cocoon add association, how to limit number of associations

I am creating a system that stores cards using Ruby/Rails/HAML - In this case there is a Card class that has many Colours (this is also a class). When creating and editing a card I am using the Cocoon gem to allow me to dynamically add colour…
6
votes
1 answer

Rails cocoon gem: populate multiple fields

I'm using the cocoon gem on my rails app and I have two nested fields inside a form (categories, subcategories). Initially I'm showing the first one only and the second one is hidden. Each time the first select fields has subcategories the second…
Dev
  • 437
  • 6
  • 25
6
votes
5 answers

Testing fields added dynamically by cocoon using rspec and capybara

I was wondering whether anybody tests fields that were dynamically added by cocoon? It's a great little time saver but all of the fields that are added dynamically have really long numerics added to the ID and name. This means that I have to skip…
DazBaldwin
  • 4,125
  • 3
  • 39
  • 43
6
votes
1 answer

Multi select file upload field with nested attributes in Rails

Currently I have a Note model which accepts nested attributes for an Attachments model, which uses Carrierwave. When adding a Note, I have a nested form to allow attaching file to the new Note: Nested form field: <%= f.file_field :image, multiple:…
Drew
  • 2,601
  • 6
  • 42
  • 65
5
votes
2 answers

Number Dynamically Generated Cocoon Fields

I've been using the Cocoon gem to dynamically generate nested fields in rails. I've run into an application where I would like to numerically label the fields generated by cocoon; something like as follows. Field 1: __________ Field 2:…
neanderslob
  • 2,633
  • 6
  • 40
  • 82
5
votes
2 answers

Cocoon/jQuery: append items to relevant table

I have a Rails view that allows many PanelItems to be added to many Panels on a Page. Models class Page < ActiveRecord::Base has_many :panels accepts_nested_attributes_for :panels, allow_destroy: true class Panel < ActiveRecord::Base has_many…
Bryan Ash
  • 4,385
  • 3
  • 41
  • 57
5
votes
1 answer

Cocoon and has_one association

I have searched on stack overflow and google to no avail. I have a person who has_one next_of_kin I can create a person with a nested form (with cocoon) and it saves perfectly. For some reason when I then go to the edit page it deletes the…
mdkrog
  • 378
  • 2
  • 13
1
2 3
33 34