I'm using Cocoon to dynamically add fields to my forms, when buttons are pressed.
The problem is that I need to run part of my JS code to apply design changes. I'm running the JS with Document Ready, however I only add those fields afterwards.
$( document ).ready(function() {
$('form.form').materialForm();
});
I'm using this simple material design framework, and I just need to run this:
$('form.form').materialForm();
Ideas?
EDIT:
HAML code:
.container
.row
.col-xs-1.col-xs-offset-2
%span.step.step-small.step-secondary 3
.col-xs-6
= f.fields_for :list_impacts do |ia|
= render "folder/folder1/impacts", f: ia
.links
= link_to_add_association 'add impacts', f, :list_impacts, partial: 'folder/folder1/impacts'
Use the callbacks . So something like
$('form.form').on('cocoon:before-insert', function(e, insertedItem) {
$(insertedItem).materialForm();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.