Felipe Valdivia
Felipe Valdivia

Reputation: 369

Rails 4 Cocoon Gem + bootstrap datepicker

I'm working with cocoon for some nested fields and everything is perfect but I have an input where I need to save dates and I'm working with bootstrap-datepicker-rails, in the first form datepicker works fine but when I push for create a new form in the second form my datepicker stop working.

I was thinking in use cocoon function for resolve it, but I don't have knowledge in javascript so I'm doing something like that:

$('#order_payments').on('cocoon:before-insert', function(e, insertedItem) {
     $('.datepicker').datepicker();
  });

But doesn't work what is the best way for resolve this problem ??

Thanks for your time !!

Upvotes: 1

Views: 511

Answers (1)

Felipe Valdivia
Felipe Valdivia

Reputation: 369

Okay I could resolve the question my code is fine just I need to add $(document).ready(function(){}); and inside put my cocoon function with the datepicker initializer.

$(document).ready(function(){
    $('.datepicker').datepicker();
    $('#order_payments').on('cocoon:after-insert', function(e, insertedItem) {
       $('.datepicker').datepicker();
    });
});

I hope this code could help to someone!

Regards !

Upvotes: 3

Related Questions