datepicker undefined in modal form loaded through AJAX

502 views
Skip to first unread message

Tobias Widlund

unread,
Nov 6, 2014, 5:22:56 AM11/6/14
to bootstrap-...@googlegroups.com
I am using the bootstrap-datepicker in a project using django and bootstrap and jquery. I have a problem when using the datepicker in a modal form loaded through AJAX.

I have one page which loads bootstrap-datepicker and uses it on a few fields in a form. This works fine as expected. However on that form I have a button which opens a bootstrap modal window containing a sub form. It is implemented by issuing an AJAX request which fetches a page only containing a <div> with the sub form, and a snipped of script to load the datepicker, because the subform also has date fields. 

The problem is that everything related to the datepicker seems to be undefined in the AJAX requested subform.

This is the snippet of code I have in my AJAX fetched form page:

<script type="text/javascript">
$(document).ajaxComplete(function()
{
    var thing = $('.date-container input');
    console.log(thing);         //prints as a valid element
    console.log($.datepicker);  //prints as undefined
    thing.datepicker({          //crashes at "cannot run undefined function"
      autoclose: true,
      todayHighlight: true
    });
});
</script>

I even tried to run this function to see if it worked:

$.fn.datepicker.defaults.format = "mm/dd/yyyy";

But $.fn.datepicker is also undefined...

Any ideas on how the datepicker can be undefined in a subform fetched through AJAX which is inserted in an already existing page where the datepicker works?

Tobias Widlund

unread,
Nov 7, 2014, 11:33:58 AM11/7/14
to bootstrap-...@googlegroups.com
Never mind, I solved it.

The problem was that a different javascript application redefined jquery to a jquery shipped with  django, causing a conflict.
Reply all
Reply to author
Forward
0 new messages