TrevorS / bootstrap3-datetimepicker-rails

This gem packages the bootstrap-datetimepicker for the Rails 3.1+ asset pipeline.
MIT License
292 stars 123 forks source link

DateTimePicker with Cocoon/Dynamically added forms #43

Closed pablougas closed 8 years ago

pablougas commented 8 years ago

I have a question on how one might get this to work with dynamically added forms.

pablougas commented 8 years ago

Hope this helps someone in the future!

$(".nested-fields").on("mouseover mouseout", ".datetimepicker", function(){ $(this).datetimepicker() })

fmoudoute commented 6 years ago

Hey @pablougas how did you integrate that code on your page please? I have been going around for a few hours now, nothing that i tried works.

pablougas commented 6 years ago

In cocoon you should be wrapping the elements in nested-fields element. Basically, the issue is that the dynamic elements hadn't been initiated with dateti e picker. I solved it by using that mouseover to quickly initialize it before someone could actually click. I could've probably done it a lot cleaner and this function will continue to reinitialize an object which isn't necessary so there could also probably use a gaurd of some sort. What's your current code look like?