18

I have been trying to use bootstrap datetimepicker and have all the components on my scripts like Moment JS, bootstrap-date-time js, and bootstrap js but I am getting g.size() is not a function error. I am trying to run the following function

$(function(){
    $('#datetimepicker').datetimepicker();
  });
Sajak Upadhyaya
  • 391
  • 1
  • 4
  • 14
  • 3
    If you use jq3.x, `$.fn.size()` method has been removed. If so, downgrade to any older jq version (2.x?). BUT maybe this has nothing to do with your issue, just it is hard to guess regarding the fact your question doesn't provide enough info – A. Wolff Jul 27 '16 at 15:17
  • I edited the question could you please check again. – Sajak Upadhyaya Jul 27 '16 at 15:21
  • Some script in there may have been passed through Google Closure Compiler in advanced optimization mode without specifying all externs. – Arnauld Jul 27 '16 at 15:23
  • @Arnauld So How can I solve my problem. I need to have a date time picker field. – Sajak Upadhyaya Jul 27 '16 at 15:24
  • If you are indeed using Google Closure Compiler, then try to temporarily disable it and see if it fixes the issue. If not, we don't have enough information to answer your question. – Arnauld Jul 27 '16 at 15:29
  • I don't know why you got a down vote - I'm getting this same (g.size() is not a function) error attempting to use the bootstrap datetimepicker (as instructed here: https://eonasdan.github.io/bootstrap-datetimepicker/Installing/, but starting with an existing bootstrap project) - I haven't been able to get to the bottom of this and am now going to choose a different date/time picker -- I'll post back here if/when I find a good one. – kris Aug 11 '16 at 22:25
  • To this date I can't get past this. I am using Angular Bootstrap datetime picker hence – Sajak Upadhyaya Aug 12 '16 at 10:36
  • try with jQuery migrate plugin – qwertzman Sep 28 '16 at 03:49

5 Answers5

22

My solution was to find a different datetime picker that actually worked

I found this one: https://github.com/xdan/datetimepicker, it was quite easy to get working:

  1. download the zip from github

  2. Include the files :

    <link href="./js/datetimepicker-master/build/jquery.datetimepicker.min.css" rel="stylesheet"> <script src="./js/datetimepicker-master/build/jquery.datetimepicker.full.min.js"></script>

  3. This HTML

    <input id="datetimepicker" type="text" />

  4. And this JS

    $.datetimepicker.setLocale('en');
    $('#datetimepicker').datetimepicker();

I got this up and working in a tiny fraction of the amount of time I'd wasted trying to get the bootstrap datetimepicker to stop giving me the g.size() error.

Of course there are many other datetime pickers available:

See this post for many more options : whats-a-good-javascript-time-picker

miken32
  • 42,008
  • 16
  • 111
  • 154
kris
  • 11,868
  • 9
  • 88
  • 110
12

.size() was removed in version 3 of jQuery, use .length instead.

In your example, replace g.size() for g.length.

Agu Dondo
  • 12,638
  • 7
  • 57
  • 68
9

The g.size error is known by the developers and exists with newer versions of jquery.

If you wish to use that datetimepicker then go back to jquery 2.1.4 or earlier.

The bug is listed here :

https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1714
Al Grant
  • 2,102
  • 1
  • 26
  • 49
  • This error in my rails app brought me here. I was using `//= require jquery3`, switching to `//= require jquery2' fixed that problem. – mohnstrudel Oct 26 '16 at 18:52
9

Please use latest bootstrap-datetimepicker to get rid of this issue. I have used below version and the error is gone.

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>

jQuery v3.3.1 is used.

Tapash
  • 762
  • 9
  • 7
  • My problem was that using Bootstrap 3 I incorrectly assumed you needed the *3.x.x* version of `bootstrap-datetimepicker` this is not correct moving to *4.x.x* version and corresponding CSS fixed my issues – James Mudd Aug 13 '19 at 13:02
  • This solved my issue!! I was using version 4.17.37. Thanks!!! – Zaehos Mar 11 '20 at 14:22
3

Check your version of jQuery. I was using the latest(3.1.1) some plugins i use were throwing this error.

according to the docs: The .size() method is deprecated as of jQuery 1.8. Use the .length property instead.

( it was removed in 3.0 )

so a simple rollback to a version before 3.0 did the trick.

edit: whoops, as A. Wolff says in the comments.

edit 2: another thing... if you want to keep your jquery version up to date, you could include the jquery-migrate plugin to your project - https://github.com/jquery/jquery-migrate

Tom
  • 97
  • 11