simple_nested_form 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_nested_form (0.0.1)
4
+ simple_nested_form (0.0.2)
5
5
  simple_form (~> 1.3.1)
6
6
 
7
7
  GEM
@@ -6,8 +6,9 @@ jQuery(function($) {
6
6
  }
7
7
 
8
8
  $("form").delegate("a[data-association]", "click", function() {
9
- var association = $(this).attr("data-association");
9
+ var association = $(this).data("association");
10
10
  var content = $("#" + association + "_fields_blueprint").html();
11
+ var limit = $(this).data("limit");
11
12
 
12
13
  var context = ($(this).closest(".fields").find("input:first").attr("name") || "").replace(new RegExp("\[[a-z]+\]$"), "");
13
14
 
@@ -27,9 +28,11 @@ jQuery(function($) {
27
28
 
28
29
  content = content.replace(new RegExp("new_" + association, "g"), new Date().getTime());
29
30
 
30
- if(fire($(this), 'nestedFields:beforeAdd', [content, association])) {
31
- $(this).before(content);
32
- $(this).trigger('nestedFields:afterAdd', [$(this).prev(), association]);
31
+ if(fire($(this), "fields:beforeadd", [content, association])) {
32
+ if(!limit || $(this).prevAll(".fields:visible").length < parseInt(limit)) {
33
+ $(this).before(content);
34
+ $(this).trigger("fields:afteradd", [$(this).prev(), association]);
35
+ }
33
36
  }
34
37
 
35
38
  return false;
@@ -39,7 +42,7 @@ jQuery(function($) {
39
42
  var destroyField = $(this).prev("input[type=hidden]")[0];
40
43
  var element = $(this).closest(".fields");
41
44
 
42
- if(fire($(this), "nestedFields:beforeRemove", [element])) {
45
+ if(fire($(this), "fields:beforeremove", [element])) {
43
46
  if (destroyField) {
44
47
  destroyField.value = "1";
45
48
  }
@@ -1,3 +1,5 @@
1
+ require "simple_form"
2
+
1
3
  module SimpleNestedForm
2
4
  class Builder < ::SimpleForm::FormBuilder
3
5
  delegate :content_tag, :link_to, :after_nested_form, :capture, :to => :@template
@@ -13,6 +15,7 @@ module SimpleNestedForm
13
15
  end
14
16
 
15
17
  options.merge!(:"data-association" => association)
18
+ options[:"data-limit"] = options.delete(:limit)
16
19
 
17
20
  after_nested_form(association) do
18
21
  model_object = object.class.reflect_on_association(association).klass.new
@@ -1,3 +1,3 @@
1
1
  module SimpleNestedForm
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -31,6 +31,10 @@ describe SimpleNestedForm::Builder do
31
31
  it "contains a class named add" do
32
32
  subject.attr("class").should include "add"
33
33
  end
34
+
35
+ it "adds a data-limit if limit was specified" do
36
+ subject.attr("data-limit").should == "3"
37
+ end
34
38
  end
35
39
  end
36
40
 
@@ -59,14 +63,14 @@ describe SimpleNestedForm::Builder do
59
63
  describe "link to add" do
60
64
  context "without a block" do
61
65
  it_should_behave_like "a link_to_add", "Add me plz" do
62
- let(:link) { builder.link_to_add("Add me plz", :tasks, :class => "add") }
66
+ let(:link) { builder.link_to_add("Add me plz", :tasks, :class => "add", :limit => 3) }
63
67
  end
64
68
  end
65
69
 
66
70
  context "with a block" do
67
71
  it_should_behave_like "a link_to_add", "A label in a block baby!" do
68
72
  let(:link) do
69
- builder.link_to_add(:tasks, :class => "add") { "A label in a block baby!" }
73
+ builder.link_to_add(:tasks, :class => "add", :limit => 3) { "A label in a block baby!" }
70
74
  end
71
75
  end
72
76
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_nested_form
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rodrigo Navarro