nested_form_fields 0.6 → 0.6.1
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 +4 -4
- data/.travis.yml +1 -1
- data/README.md +4 -5
- data/lib/assets/javascripts/nested_form_fields.js.coffee +7 -5
- data/lib/nested_form_fields.rb +14 -8
- data/lib/nested_form_fields/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af179df78241f65dc54725b434303052e162b93a
|
4
|
+
data.tar.gz: f4a8b1c8590a307cf7518ac56c0914390ea3ca5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a84704f681204e122cd58e285af477ed0f87eb531d352a420dfe43ffa8002fdb74844b7ed15493340da51eaa760f39a1063a17cb35d268e6023f924ab2f52c9a
|
7
|
+
data.tar.gz: 2c7d7d4ec8c595bf1fe6f24826e1001e8cfbd7f18828da8d08d428c1385509a283be80634971529fbf027e2c6e976a2da3d4ca769dc4fb946354fa3b5a3cf1ba
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -58,12 +58,12 @@ You can change the link text of *remove_nested_fields_link* and *add_nested_fiel
|
|
58
58
|
...
|
59
59
|
f.add_nested_fields_link :videos, 'Add another funtastic video'
|
60
60
|
|
61
|
-
You can add classes to the *remove_nested_fields_link* and *add_nested_fields_link* like this:
|
61
|
+
You can add classes/attributes to the *remove_nested_fields_link* and *add_nested_fields_link* like this:
|
62
62
|
|
63
63
|
...
|
64
|
-
ff.remove_nested_fields_link 'Remove me', class: 'btn btn-danger'
|
64
|
+
ff.remove_nested_fields_link 'Remove me', class: 'btn btn-danger', role: 'button'
|
65
65
|
...
|
66
|
-
f.add_nested_fields_link :videos, 'Add another funtastic video', class: 'btn btn-primary'
|
66
|
+
f.add_nested_fields_link :videos, 'Add another funtastic video', class: 'btn btn-primary', role: 'button'
|
67
67
|
|
68
68
|
You can change the type of the element wrapping the nested fields using the *wrapper_tag* option:
|
69
69
|
|
@@ -101,5 +101,4 @@ CoffeeScript sample:
|
|
101
101
|
|
102
102
|
## Contributers
|
103
103
|
|
104
|
-
|
105
|
-
- [Levente Tamas](https://github.com/tamisoft)
|
104
|
+
https://github.com/ncri/nested_form_fields/graphs/contributors
|
@@ -5,15 +5,16 @@ nested_form_fields.bind_nested_forms_links = () ->
|
|
5
5
|
$('body').on 'click', '.add_nested_fields_link', ->
|
6
6
|
$link = $(this)
|
7
7
|
object_class = $link.data('object-class')
|
8
|
-
$.event.trigger("fields_adding.nested_form_fields",{object_class: object_class});
|
9
8
|
association_path = $link.data('association-path')
|
9
|
+
added_index = $(".nested_#{association_path}").length
|
10
|
+
$.event.trigger("fields_adding.nested_form_fields",{object_class: object_class, added_index: added_index, association_path: association_path});
|
10
11
|
$template = $("##{association_path}_template")
|
11
12
|
|
12
13
|
template_html = $template.html()
|
13
14
|
|
14
15
|
# insert association indexes
|
15
16
|
index_placeholder = "__#{association_path}_index__"
|
16
|
-
template_html = template_html.replace(new RegExp(index_placeholder,"g"),
|
17
|
+
template_html = template_html.replace(new RegExp(index_placeholder,"g"), added_index)
|
17
18
|
|
18
19
|
# replace child template div tags with script tags to avoid form submission of templates
|
19
20
|
$parsed_template = $(template_html)
|
@@ -23,20 +24,21 @@ nested_form_fields.bind_nested_forms_links = () ->
|
|
23
24
|
$child.replaceWith($("<script id='#{$child.attr('id')}' type='text/html' />").html($child.html()))
|
24
25
|
|
25
26
|
$template.before( $parsed_template )
|
26
|
-
$.event.trigger("fields_added.nested_form_fields",{object_class: object_class});
|
27
|
+
$.event.trigger("fields_added.nested_form_fields",{object_class: object_class, added_index: added_index, association_path: association_path});
|
27
28
|
false
|
28
29
|
|
29
30
|
$('body').off("click", '.remove_nested_fields_link')
|
30
31
|
$('body').on 'click', '.remove_nested_fields_link', ->
|
31
32
|
$link = $(this)
|
32
33
|
object_class = $link.data('object-class')
|
33
|
-
$.event.trigger("fields_removing.nested_form_fields",{object_class: object_class});
|
34
34
|
delete_association_field_name = $link.data('delete-association-field-name')
|
35
|
+
removed_index = parseInt(delete_association_field_name.match('(\\d+\\]\\[_destroy])')[0][0])
|
36
|
+
$.event.trigger("fields_removing.nested_form_fields",{object_class: object_class, delete_association_field_name: delete_association_field_name, removed_index: removed_index });
|
35
37
|
$nested_fields_container = $link.parents(".nested_fields").first()
|
36
38
|
$nested_fields_container.before "<input type='hidden' name='#{delete_association_field_name}' value='1' />"
|
37
39
|
$nested_fields_container.hide()
|
38
40
|
$nested_fields_container.find('input[required]:hidden').removeAttr('required')
|
39
|
-
$.event.trigger("fields_removed.nested_form_fields",{object_class: object_class});
|
41
|
+
$.event.trigger("fields_removed.nested_form_fields",{object_class: object_class, delete_association_field_name: delete_association_field_name, removed_index: removed_index});
|
40
42
|
false
|
41
43
|
|
42
44
|
$(document).on "page:change", ->
|
data/lib/nested_form_fields.rb
CHANGED
@@ -23,16 +23,22 @@ module ActionView::Helpers
|
|
23
23
|
end
|
24
24
|
|
25
25
|
|
26
|
-
def add_nested_fields_link association, text = nil,
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
def add_nested_fields_link association, text = nil, html_options = {}
|
27
|
+
html_class = html_options.delete(:class) || {}
|
28
|
+
html_data = html_options.delete(:data) || {}
|
29
|
+
@template.link_to text || "Add #{association.to_s.singularize.humanize}", '', {
|
30
|
+
class: "#{html_class} add_nested_fields_link",
|
31
|
+
data: { association_path: association_path(association.to_s), object_class: association.to_s.singularize }.merge(html_data)
|
32
|
+
}.merge(html_options)
|
30
33
|
end
|
31
34
|
|
32
|
-
def remove_nested_fields_link text = nil,
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
def remove_nested_fields_link text = nil, html_options = {}
|
36
|
+
html_class = html_options.delete(:class) || {}
|
37
|
+
html_data = html_options.delete(:data) || {}
|
38
|
+
@template.link_to text || 'x', '', {
|
39
|
+
class: "#{html_class} remove_nested_fields_link",
|
40
|
+
data: { delete_association_field_name: delete_association_field_name, object_class: @object.class.name.underscore.downcase }.merge(html_data)
|
41
|
+
}.merge(html_options)
|
36
42
|
end
|
37
43
|
|
38
44
|
|
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:
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nico Ritsche
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|