0

I'm no stranger to jQuery, and I have a lot of experience with Bootstrap Datepicker and have never had an issue. This project, however, has a lot of legacy configurations for jQuery UI Datepicker which have more or less boxed me into using it. For whatever reason, though, I can't seem to get it to initialize. I'm using jQuery and jQuery UI from the CDN and I'm not trying to do anything fancy yet.

Below is how everything is set up in its most basic state.

CDN:

<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>

Initialization:

<script type="text/javascript">
  $("#checkin").datepicker();
</script>

HTML:

<div class="travel-dates small">
  <div class="date">
    <label for="checkin">Check in</label>
    <div class="input-group form-group">
      <input name='checkin' id="checkin" class="form-control input-sm" placeholder="mm/dd/yyyy" required="" type="text"> 
      <span class="input-group-btn">
        <button type="button" tabindex="-1" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-calendar"></i></button>
      </span>
    </div>
  </div>
  <div class="date">
    <label for="checkout">Check out</label>
    <div class="input-group form-group">
      <input name="checkout" id="checkout" class="form-control input-sm" placeholder="mm/dd/yyyy" required="" type="text"> 
      <span class="input-group-btn">
        <button type="button" tabindex="-1" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-calendar"></i></button>
      </span>
    </div>
  </div>
</div>

I tried calling the datepicker on click as well using $("#checkin").datepicker("show"), and when I do, I get the error "t is undefined," which references datepicker in its trace.

I must be missing something, or doing something wrong, but I can't get this to work for the life of me. I've crawled through all the other SO answers on the topic, and haven't found anything that helped. I'm honestly at the point of deciding it's easier to redo all of the cool things they did for jQuery UI Datepicker with something else rather than try to get this to work with so little to go on in the way of errors. Any help or advice would be much appreciated.

UPDATE:

What I posted above ended up working when I copied it back over. The site I'm working on was an angular site that has been ported to PHP and we still had some angular classes on my inputs. These classes are not defined in our current CSS files, we just hadn't gotten around to removing them. For some reason, removing those classes did the trick. And to clarify, the calendar wasn't hidden or display: none, it was failing to initialize without error. Everything is working now, but I'd be curious if anyone can solve the mystery of why the extra undefined classes were causing it to fail.

Original HTML:

<div class="travel-dates small ng-isolate-scope">
  <div class="date">
    <label for="checkin" class="ng-scope">Check in</label>
    <div class="input-group form-group">
      <input name='checkin' id="checkin" class="form-control input-sm ng-pristine ng-invalid ng-invalid-required hasDatepicker" placeholder="mm/dd/yyyy" required="" type="text"> 
      <span class="input-group-btn">
        <button type="button" tabindex="-1" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-calendar"></i></button>
      </span>
    </div>
  </div>
  <div class="date">
    <label for="checkout" class="ng-scope">Check out</label>
    <div class="input-group form-group">
      <input name="checkout" id="checkout" class="form-control input-sm ng-pristine ng-invalid ng-invalid-required hasDatepicker" placeholder="mm/dd/yyyy" required="" type="text"> 
      <span class="input-group-btn">
        <button type="button" tabindex="-1" class="btn btn-default btn-sm" disabled="disabled"><i class="glyphicon glyphicon-calendar"></i></button>
      </span>
    </div>
  </div>
</div>

1 Answer 1

1

Am unable to replicate the issue you as you described it. I suspect that something is causing an issue with loading jQuery UI.

$(function() {
  $("#checkin").datepicker();
});
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<div class="travel-dates small">
  <div class="date">
    <label for="checkin">Check in</label>
    <div class="input-group form-group">
      <input name='checkin' id="checkin" class="form-control input-sm" placeholder="mm/dd/yyyy" required="" type="text">
      <span class="input-group-btn">
        <button type="button" tabindex="-1" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-calendar"></i></button>
      </span>
    </div>
  </div>
  <div class="date">
    <label for="checkout">Check out</label>
    <div class="input-group form-group">
      <input name="checkout" id="checkout" class="form-control input-sm" placeholder="mm/dd/yyyy" required="" type="text">
      <span class="input-group-btn">
        <button type="button" tabindex="-1" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-calendar"></i></button>
      </span>
    </div>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

2 Comments

It seems to load fine, as it specifically throws the "t is undefined error." But, yes, I see that it works here. Other than jQuery UI failing to load, can you think of any reason for this to fail?
Thanks, you reminded me to keep it simple. I had stripped some classes from my HTML to post it here to keep lines short. It worked here, and not on the site, so I took this simplified working code and copied it back. Sure enough, it worked. No idea what classes were breaking it or why, but it works now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.