Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: $ is not defined #13

Open
lowjumpingfrog opened this issue Nov 27, 2017 · 6 comments
Open

Uncaught ReferenceError: $ is not defined #13

lowjumpingfrog opened this issue Nov 27, 2017 · 6 comments

Comments

@lowjumpingfrog
Copy link

I am using Django 1.11, Python 3 and Crispy Forms. The form renders properly but, the a javascript error pops up complaining about an Uncaught Reference of:
$("#id_work_start_time_pickers:has(input:not([readonly],[disabled]))").datetimepicker({"format": "YYYY-MM-DD HH:mm:ss", "ignoreReadonly": true, "sideBySide": true});
The generated HTML looks like:

<div id="div_id_work_start_time" class="form-group">
<label for="id_work_start_time" class="control-label  requiredField">
                Work start time<span class="asteriskField">*</span>
</label>
<div class="controls ">
<div class="input-group date" id="id_work_start_time_pickers">
<input class="form-control datetimepicker form-control" id="id_work_start_time" name="work_start_time" required="True" type="text"/>
<span class="input-group-addon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div>
<script>
      $(function(){
        $("#id_work_start_time_pickers:has(input:not([readonly],[disabled]))").datetimepicker({"format": "YYYY-MM-DD HH:mm:ss", "ignoreReadonly": true, "sideBySide": true});
      });
    </script>
</div>

Not sure where read only is being set? Any Ideas. I tried passing the option to ignore. But, no luck

@samuelcolvin
Copy link
Member

samuelcolvin commented Nov 27, 2017 via email

@lowjumpingfrog
Copy link
Author

Yes, from a cdn: code.jquery.com/jquery-3.2.1.js I usually load it at the bottom of the page. Just before the bootstrap js: maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js

@samuelcolvin
Copy link
Member

samuelcolvin commented Nov 28, 2017 via email

@lowjumpingfrog
Copy link
Author

When I move the script loads to the head tag I get this error:

Uncaught TypeError: input.size is not a function
    at dateTimePicker (bootstrap-datetimepicker.js:2254)
    at HTMLDivElement.<anonymous> (bootstrap-datetimepicker.js:2309)
    at Function.each (jquery-3.2.1.js:362)
    at jQuery.fn.init.each (jquery-3.2.1.js:157)
    at jQuery.fn.init.$.fn.datetimepicker (bootstrap-datetimepicker.js:2304)
    at HTMLDocument.<anonymous> ((index):39)
    at mightThrow (jquery-3.2.1.js:3583)
    at process (jquery-3.2.1.js:3651)

@samuelcolvin
Copy link
Member

samuelcolvin commented Nov 28, 2017 via email

@felix-engelmann
Copy link
Contributor

felix-engelmann commented Jan 11, 2018

@lowjumpingfrog If you want to keep your JS imports at the bottom, you could wrap the jQuery calls inside a defer loop of vanilla JS. The easiest is by subclassing it and overwriting js_template

 js_template = """
 <script>
     (function defer() {
           if (window.jQuery) {
                 $(function(){
                     $("#%(picker_id)s:has(input:not([readonly],[disabled]))").datetimepicker(%(options)s);
                 });
           } else {
                setTimeout(function() { defer() }, 50);
           }
     })();
 </script>"""

or use PR #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants