nested_form_fields 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9dfe025c7ab16a005c19f09f5bded4a0b2577cd0
4
- data.tar.gz: a14a8387257439f399e6d8dc7e7b228cd840810e
3
+ metadata.gz: 79ceb58abeaaaed91ae93d7f48846edc50845e26
4
+ data.tar.gz: 23e8ccd772a4b458fff7dff9cb6e84f21333502c
5
5
  SHA512:
6
- metadata.gz: 425b92d13906049d6e77990cd51c1fd866e1f49b496aa10cd22a092fbd715e41dd286ba84d1b91fd435bbd2e780d84eda5eca0c0685c3e58bc6e316352a593a5
7
- data.tar.gz: 91a36c24913008f007d8c0e2f0f1f68a86e827ae5e65b96ad6aae32ec1a84632924b499f5984d8f20a788a600d5d93c7861320296557a53f8ca4cdadc266761f
6
+ metadata.gz: 0c849a9f26a8052210b5355c2dedfb88b27f11688b94ca2abfb127e39ef2c27c2a733e24479608a3d57b9ac7b225b111b0e175e74514d395c97f7120a226f2fa
7
+ data.tar.gz: 73c52e1d17e016e32d85f948c1c0aeb0eac3dc8e8a07f374fda4a2b4425e751035ddb272961b983ede82aafdc9cb4061499f09d4912d65d4fa66f0975548c0cc
data/README.md CHANGED
@@ -20,7 +20,7 @@ And then execute:
20
20
 
21
21
  $ bundle
22
22
 
23
- In your application.js file add:
23
+ In your application.js file add:
24
24
 
25
25
  //= require nested_form_fields
26
26
 
@@ -31,7 +31,7 @@ Assume you have a user model with nested videos:
31
31
  class User < ActiveRecord::Base
32
32
  has_many :videos
33
33
  accepts_nested_attributes_for :videos, allow_destroy: true
34
- end
34
+ end
35
35
 
36
36
  Use the *nested_fields_for* helper inside your user form to add the video fields:
37
37
 
@@ -65,7 +65,11 @@ You can change the type of the element wrapping the nested fields using the *wra
65
65
  The default wrapper element is a fieldset. To add legend element to the fieldset use:
66
66
 
67
67
  = f.nested_fields_for :videos, legend: "Video" do |ff|
68
-
68
+
69
+ You can pass options like you would to the `content_tag` method by nesting them in a `:wrapper_options` hash:
70
+
71
+ = f.nested_fields_for :videos, wrapper_options: { class: 'row' } do |ff|
72
+
69
73
  There are 4 javascipt events firing before and after addition/removal of the fields in the *nested_form_fields* namespace. Namely:
70
74
  fields_adding, fields_added, fields_removing, fields_removed.
71
75
 
@@ -1,3 +1,3 @@
1
1
  module NestedFormFields
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -16,6 +16,7 @@ module ActionView::Helpers
16
16
  fields_options[:builder] ||= options[:builder]
17
17
  fields_options[:parent_builder] = self
18
18
  fields_options[:wrapper_tag] ||= :fieldset
19
+ fields_options[:wrapper_options] ||= {}
19
20
  fields_options[:namespace] = fields_options[:parent_builder].options[:namespace]
20
21
 
21
22
  return fields_for_has_many_association_with_template(record_name, record_object, fields_options, block)
@@ -49,7 +50,7 @@ module ActionView::Helpers
49
50
 
50
51
  output = ActiveSupport::SafeBuffer.new
51
52
  association.each do |child|
52
- output << nested_fields_wrapper(association_name, options[:wrapper_tag], options[:legend]) do
53
+ output << nested_fields_wrapper(association_name, options[:wrapper_tag], options[:legend], options[:wrapper_options]) do
53
54
  fields_for_nested_model("#{name}[#{options[:child_index] || nested_child_index(name)}]", child, options, block)
54
55
  end
55
56
  end
@@ -73,7 +74,7 @@ module ActionView::Helpers
73
74
  id: template_id(association_name),
74
75
  class: for_template ? 'form_template' : nil,
75
76
  style: for_template ? 'display:none' : nil ) do
76
- nested_fields_wrapper(association_name, options[:wrapper_tag], options[:legend]) do
77
+ nested_fields_wrapper(association_name, options[:wrapper_tag], options[:legend], options[:wrapper_options]) do
77
78
  association_class = (options[:class_name] || association_name).to_s.classify.constantize
78
79
  fields_for_nested_model("#{name}[#{index_placeholder(association_name)}]",
79
80
  association_class.new,
@@ -82,7 +83,6 @@ module ActionView::Helpers
82
83
  end
83
84
  end
84
85
 
85
-
86
86
  def template_id association_name
87
87
  "#{association_path(association_name)}_template"
88
88
  end
@@ -99,13 +99,18 @@ module ActionView::Helpers
99
99
  "#{object_name}[_destroy]"
100
100
  end
101
101
 
102
-
103
- def nested_fields_wrapper association_name, wrapper_element_type, legend
104
- @template.content_tag wrapper_element_type, class: "nested_fields nested_#{association_path(association_name)}" do
102
+ def nested_fields_wrapper(association_name, wrapper_element_type, legend, wrapper_options)
103
+ wrapper_options = add_default_classes_to_wrapper_options(association_name, wrapper_options)
104
+ @template.content_tag wrapper_element_type, wrapper_options do
105
105
  (wrapper_element_type==:fieldset && !legend.nil?)? ( @template.content_tag(:legend, legend, class: "nested_fields") + yield ) : yield
106
106
  end
107
107
  end
108
108
 
109
+ def add_default_classes_to_wrapper_options(association_name, wrapper_options)
110
+ default_classes = ["nested_fields", "nested_#{association_path(association_name)}"]
111
+ wrapper_options[:class] = wrapper_options[:class].is_a?(String) ? wrapper_options[:class].split(" ") : wrapper_options[:class].to_a
112
+ wrapper_options[:class] += default_classes
113
+ wrapper_options
114
+ end
109
115
  end
110
-
111
116
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nested_form_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nico Ritsche
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-15 00:00:00.000000000 Z
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -252,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
252
  version: '0'
253
253
  requirements: []
254
254
  rubyforge_project:
255
- rubygems_version: 2.1.11
255
+ rubygems_version: 2.2.2
256
256
  signing_key:
257
257
  specification_version: 4
258
258
  summary: Rails gem for dynamically adding and removing nested has_many association