Skip to content
This repository was archived by the owner on Jul 11, 2019. It is now read-only.

Commit 042dd1d

Browse files
committed
Delay the widget initialization
Many people like to place {{ form.media }} at the end of the page, in this case jQuery would not be loaded yet when the initialization runs (js_template). I'm not a javascript guy, perhaps there is a better way to delay the widget initialization, but this worked for me.
1 parent 8aa28a6 commit 042dd1d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

bootstrap3_datetime/widgets.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,16 @@ def conv_datetime_format_js2py(cls, format):
7878

7979
js_template = '''
8080
<script>
81-
$(function() {
82-
$("#%(picker_id)s").datetimepicker(%(options)s);
83-
});
81+
(function(window) {
82+
var callback = function() {
83+
$(function(){$("#%(picker_id)s").datetimepicker(%(options)s);});
84+
};
85+
if(window.addEventListener)
86+
window.addEventListener("load", callback, false);
87+
else if (window.attachEvent)
88+
window.attachEvent("onload", callback);
89+
else window.onload = callback;
90+
})(window);
8491
</script>'''
8592

8693
def __init__(self, attrs=None, format=None, options=None, div_attrs=None, icon_attrs=None):

0 commit comments

Comments
 (0)