Template is now saved under data-association attribute to prevent those extra blank records when submitting form.
This commit is contained in:
parent
2be9a44303
commit
657e478801
|
@ -61,12 +61,9 @@ module Cocoon
|
|||
html_options[:'data-association'] = association.to_s.singularize
|
||||
|
||||
new_object = f.object.class.reflect_on_association(association).klass.new
|
||||
model_name = new_object.class.name.underscore
|
||||
hidden_div = content_tag('div', :id => "#{model_name}_fields_template", :style => "display:none;") do
|
||||
render_association(association, f, new_object)
|
||||
end
|
||||
html_options[:'data-template'] = CGI.escapeHTML(render_association(association, f, new_object))
|
||||
|
||||
hidden_div.html_safe + link_to(name, '#', html_options )
|
||||
link_to(name, '#', html_options )
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ $(document).ready(function() {
|
|||
|
||||
$('.add_fields').live('click', function() {
|
||||
var assoc = $(this).attr('data-association');
|
||||
var content = $(this).siblings('#' + assoc + '_fields_template').html();
|
||||
var content = $(this).attr('data-template');
|
||||
var insertionPosition = $(this).attr('data-association-insertion-position');
|
||||
var insertionNode = $(this).attr('data-association-insertion-node');
|
||||
var regexp_braced = new RegExp('\\[new_' + assoc + '\\]', 'g');
|
||||
|
|
|
@ -15,18 +15,18 @@ describe Cocoon do
|
|||
@tester = TestClass.new
|
||||
@post = Post.new
|
||||
@form_obj = stub(:object => @post)
|
||||
@tester.stub(:render_association).and_return('form')
|
||||
@tester.stub(:render_association).and_return('form<tag>')
|
||||
end
|
||||
|
||||
context "without a block" do
|
||||
it "should accept a name" do
|
||||
result = @tester.link_to_add_association('add something', @form_obj, :comments)
|
||||
result.to_s.should == '<div id="comment_fields_template" style="display:none;">form</div><a href="#" class="add_fields" data-association="comment">add something</a>'
|
||||
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-template="form&lt;tag&gt;">add something</a>'
|
||||
end
|
||||
|
||||
it "should accept html options and pass them to link_to" do
|
||||
result = @tester.link_to_add_association('add something', @form_obj, :comments, {:class => 'something silly'})
|
||||
result.to_s.should == "<div id=\"comment_fields_template\" style=\"display:none;\">form</div><a href=\"#\" class=\"something silly add_fields\" data-association=\"comment\">add something</a>"
|
||||
result.to_s.should == '<a href="#" class="something silly add_fields" data-association="comment" data-template="form&lt;tag&gt;">add something</a>'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -35,14 +35,14 @@ describe Cocoon do
|
|||
result = @tester.link_to_add_association(@form_obj, :comments) do
|
||||
"some long name"
|
||||
end
|
||||
result.to_s.should == "<div id=\"comment_fields_template\" style=\"display:none;\">form</div><a href=\"#\" class=\"add_fields\" data-association=\"comment\">some long name</a>"
|
||||
result.to_s.should == '<a href="#" class="add_fields" data-association="comment" data-template="form&lt;tag&gt;">some long name</a>'
|
||||
end
|
||||
|
||||
it "should accept html options and pass them to link_to" do
|
||||
result = @tester.link_to_add_association(@form_obj, :comments, {:class => 'floppy disk'}) do
|
||||
"some long name"
|
||||
end
|
||||
result.to_s.should == "<div id=\"comment_fields_template\" style=\"display:none;\">form</div><a href=\"#\" class=\"floppy disk add_fields\" data-association=\"comment\">some long name</a>"
|
||||
result.to_s.should == '<a href="#" class="floppy disk add_fields" data-association="comment" data-template="form&lt;tag&gt;">some long name</a>'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue