I'm at a loss why this is happening, everyone around me is tossing their hands up. So I'll put it to the hive mind. This is some serious simple shit. Why it's causing angst is part of the problem in itself.
The problem. Building an app that needs to not require gems beyond rails and ORM driver. This would be solved with cocoon but the delivery rule....
Building forms on the fly that have has_many associations, needs a wee bit of mark up, javascript and logic to pull off here are those bits.
Inside the application helper we have a method for building the button on the form to add a copy of the form snippet to the markup.
Then we have a bit of jquery to handle the on_click
The markup is virtually identical between the two forms i'm using this on. One works as expected, the other submits the parent form.
any insight?
The problem. Building an app that needs to not require gems beyond rails and ORM driver. This would be solved with cocoon but the delivery rule....
Building forms on the fly that have has_many associations, needs a wee bit of mark up, javascript and logic to pull off here are those bits.
Inside the application helper we have a method for building the button on the form to add a copy of the form snippet to the markup.
Code:
def add_child_button(name, association,target)
content_tag(:button,name,
:class => "add_child",
:"data-association" => association,
:target => target)
end
Then we have a bit of jquery to handle the on_click
Code:
$('.add_child').click(function() {
var association = $(this).attr('data-association');
var target = $(this).attr('target');
var regexp = new RegExp('new_' + association, 'g');
var new_id = new Date().getTime();
var Dest = (target == '') ? $(this).parent() : $('#'+target);
console.log(Dest);
Dest.append(window[association+'_fields'].replace(regexp, new_id));
return false;
});
The markup is virtually identical between the two forms i'm using this on. One works as expected, the other submits the parent form.
any insight?