0

This is the error i am facing:

Uncaught TypeError: Object [object Object] has no method 'datepicker' myquery.js:13
(anonymous function) myquery.js:13
fire jquery.js:3049
self.fireWith jquery.js:3161
jQuery.extend.ready jquery.js:434
completed

the code of myquery.js is below:

jQuery(function($){
    $("#datepicker").datepicker({
        dateFormat: 'yy-mm-dd'
    });
});

In my application.js i have:

//= require jquery
//= require myquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

And in my application.html.erb i have this:

  <%= stylesheet_link_tag    "http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css" %>
true %>

and lastly my index.html.erb says:

<label for="date">Date</label>
<input type="text" id="datepicker"></p>

i have tried almost all the answers on stackoverflow but no gain. plz tell me what to do...

1

3 Answers 3

1

You have to load jquery ui first

And then load myquery.js

because datepicker() is the method of jquery ui.

So, your javascript load order sholud be the following...

//= require jquery
//= require jquery_ujs
//= require myquery
//= require turbolinks
//= require_tree
Sign up to request clarification or add additional context in comments.

2 Comments

is it //==require jquery_ujs or jquery_uis?
it is //= require jquery_ujs or you can check the following link github.com/rails/jquery-ujs
0

It seams as jQuery UI js file is not loaded before you use datepicker method. Change the order of require(jquery_ujs before myquery):

//= require jquery
//= require jquery_ujs
//= require myquery
//= require turbolinks
//= require_tree .

Comments

0

same require order as write Hasib Hasan Arnab and

$( document ).ready(function() {
  $("#datepicker").datepicker({
    dateFormat: 'yy-mm-dd'
  });
});

Comments

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.