nested_form_fields 0.6 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6db5cc91c0cef2549bf50762a6d4b383f9730b26
4
- data.tar.gz: cd22dfe2aeb9c8731d879b14ade9cfb8035da3a3
3
+ metadata.gz: af179df78241f65dc54725b434303052e162b93a
4
+ data.tar.gz: f4a8b1c8590a307cf7518ac56c0914390ea3ca5b
5
5
  SHA512:
6
- metadata.gz: 176410133dfd4a1d4bbde0c2bb84b19bb342e95767c3356e56e88d23a8fbd7546ef1ff7c92ab11ade79faa87d945ba7f86a8996144dccf19141d87ef07129992
7
- data.tar.gz: 38c5f5147af0c38d614adf68ce07afd9160158db7f73acb869994f52d743613dd88bb9f16dae1258e2ea97cbe0e06ebaba888d3df38f32f040ba64c6ef8d2d4c
6
+ metadata.gz: a84704f681204e122cd58e285af477ed0f87eb531d352a420dfe43ffa8002fdb74844b7ed15493340da51eaa760f39a1063a17cb35d268e6023f924ab2f52c9a
7
+ data.tar.gz: 2c7d7d4ec8c595bf1fe6f24826e1001e8cfbd7f18828da8d08d428c1385509a283be80634971529fbf027e2c6e976a2da3d4ca769dc4fb946354fa3b5a3cf1ba
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  rvm:
2
- - 1.9.3
2
+ - 2.1.3
3
3
  before_script:
4
4
  - "export DISPLAY=:99.0"
5
5
  - "sh -e /etc/init.d/xvfb start"
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
- - [Tom Riley](https://github.com/tomriley)
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"), $(".nested_#{association_path}").length)
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", ->
@@ -23,16 +23,22 @@ module ActionView::Helpers
23
23
  end
24
24
 
25
25
 
26
- def add_nested_fields_link association, text = nil, options = {}
27
- @template.link_to text || "Add #{association.to_s.singularize.humanize}", '',
28
- class: "#{options[:class]} add_nested_fields_link",
29
- data: { association_path: association_path(association.to_s), object_class: association.to_s.singularize }
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, options = {}
33
- @template.link_to text || 'x', '',
34
- class: "#{options[:class]} remove_nested_fields_link",
35
- data: { delete_association_field_name: delete_association_field_name, object_class: @object.class.name.underscore.downcase }
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
 
@@ -1,3 +1,3 @@
1
1
  module NestedFormFields
2
- VERSION = "0.6"
2
+ VERSION = "0.6.1"
3
3
  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.6'
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: 2014-12-06 00:00:00.000000000 Z
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails