0

Currently building a grails application here and I am using jQuerydaterangeslider and facing this error (which clearly many have faced before) in my console

Error : Uncaught TypeError: Object [object Object] has no method 'dateRangeSlider'

Also, in my network tab, error :

jquery-10.1.2.min.map is not found

I checked online and understood the problem could lie in mainly having multiple jquery being called and it's conflict among themselves or other js libraries. I am also using prototype.js, so this conflict is also there. I had already removed this using noConflict(), still the error persits

I tried

  • Removing all and having only one jquery library (either 10.1.2 or 10.1.2.min or only ui-10.1.4) - none worked
  • using jquery.noConflict with prototype - Works for my prototype code, but same error in jquery part.

Links referred/used :

  1. jQuery Uncaught TypeError: Object[object Object] has no method slider
  2. Uncaught TypeError: Object [object Object] has no method "fancybox"
  3. jQuery's jquery-1.10.2.min.map is triggering a 404 (Not Found)

UPDATE :

-After playing around with the index.gsp codes and shifting around the jquery conflict and keeping only one copy, I have managed to print the dateslider now, but I am also using highcharts and the new error is as follows :

Uncaught TypeError: Object [object Object] has no method 'highcharts'

Which is exactly same now,

New index.gsp code:

<g:javascript src="d3.v3.min.js"/>
<g:javascript src="highcharts.js"/>
<g:javascript src="exporting.js"/>
<g:javascript src="prototype.js"/>

<script>
var $j = jQuery.noConflict();
</script>

<g:javascript src="jQuery-ui-1.10.4.custom.js"/>

<g:javascript src="jQDateRangeSlider-min.js"/>
<g:javascript src="jQDateRangeSlider-withRuler-min.js"/>
<g:javascript src="jQRangeSliderLabel.js"/>

Output of console :

console.log("$.fn.jquery for version:",$.fn  && $.fn.jquery);
$.fn.jquery for version: undefined VM33:2
undefined
console.log("$.fn.dateRangeSlider:",$.fn && jQuery.fn.dateRangeSlider);
$.fn.dateRangeSlider: undefined VM34:2
undefined
console.log("jQuery.fn for verson:",jQuery.fn && jQuery.fn.jquery);
jQuery.fn for verson: 1.10.2 VM35:2
undefined
console.log("jQuery.fn dateRangeSlider",jQuery.fn && jQuery.fn.dateRangeSlider);
jQuery.fn dateRangeSlider function ( options ) {
        var isMethodCall = typeof options === "string",
            args = slice.call( arguments, 1 ),
            returnValue = this;

        // allow multiple hashes to be passed on init
        options = !isMethodCall && args.length ?
            $.widget.extend.apply( null, [ options ].concat(args) ) :
            options;

        if ( isMethodCall ) {
            this.each(function() {
                var methodValue,
                    instance = $.data( this, fullName );
                if ( !instance ) {
                    return $.error( "cannot call methods on " + name + " prior to initialization; " +
                        "attempted to call method '" + options + "'" );
                }
                if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
                    return $.error( "no such method '" + options + "' for " + name + " widget instance" );
                }
                methodValue = instance[ options ].apply( instance, args );
                if ( methodValue !== instance && methodValue !== undefined ) {
                    returnValue = methodValue && methodValue.jquery ?
                        returnValue.pushStack( methodValue.get() ) :
                        methodValue;
                    return false;
                }
            });
        } else {
            this.each(function() {
                var instance = $.data( this, fullName );
                if ( instance ) {
                    instance.option( options || {} )._init();
                } else {
                    $.data( this, fullName, new object( options, this ) );
                }
            });
        }

        return returnValue;
    } VM36:2
undefined
console.log("$j fn jquery",$j.fn  && $j.fn.jquery);
$j fn jquery 1.10.2 VM37:2
undefined
console.log("$j fn dateRangeSlider:",$j.fn && $j.fn.dateRangeSlider);
$j fn dateRangeSlider: function ( options ) {
        var isMethodCall = typeof options === "string",
            args = slice.call( arguments, 1 ),
            returnValue = this;

        // allow multiple hashes to be passed on init
        options = !isMethodCall && args.length ?
            $.widget.extend.apply( null, [ options ].concat(args) ) :
            options;

        if ( isMethodCall ) {
            this.each(function() {
                var methodValue,
                    instance = $.data( this, fullName );
                if ( !instance ) {
                    return $.error( "cannot call methods on " + name + " prior to initialization; " +
                        "attempted to call method '" + options + "'" );
                }
                if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
                    return $.error( "no such method '" + options + "' for " + name + " widget instance" );
                }
                methodValue = instance[ options ].apply( instance, args );
                if ( methodValue !== instance && methodValue !== undefined ) {
                    returnValue = methodValue && methodValue.jquery ?
                        returnValue.pushStack( methodValue.get() ) :
                        methodValue;
                    return false;
                }
            });
        } else {
            this.each(function() {
                var instance = $.data( this, fullName );
                if ( instance ) {
                    instance.option( options || {} )._init();
                } else {
                    $.data( this, fullName, new object( options, this ) );
                }
            });
        }

        return returnValue;
    } VM38:2
undefined
  • Is the position of defining jquery.noconflict important? I shifted it before jquery and pushed prototype to the top, this got the dateslider working. But now, highcharts has the same problem which I am accessing by the following and this is where the error is :

    $j(function () { $j('#container1').highcharts({

Any ideas will be highly appreciated!

Community
  • 1
  • 1
Pravin
  • 461
  • 5
  • 26
  • You have `` multiple times. Maybe try and remove the last one. – HMR Jul 22 '14 at 03:54
  • As I have said, I have tried removing each jquery once, but nothing is working yet – Pravin Jul 22 '14 at 06:07
  • The code as posted in your question would likely produce the error you describe. – HMR Jul 22 '14 at 06:23
  • So, can you please tell me how to modify the code to make it work? I have tried removing and having individual jquery libraries only, but it still didn't help. Any other ideas? should i define noconflict for each of jqueries libs individually? – Pravin Jul 22 '14 at 07:33
  • Also, I have used this exact same code for another grails application which works perfectly, but in this app, it's consistently giving me this error, is there any way out? – Pravin Jul 22 '14 at 08:19
  • I've added an answer; you can't have used the exact same code as that code would not have worked as well if it were the exact same. Maybe in the other code you've wrapped jQuery code in document.ready and pass `$`. Hope the answer can help out. If you still can't solve it please update your answer with the output of the console.logs and the current html code of your page. – HMR Jul 22 '14 at 08:30
  • Why would you put jQuery.noConflict before even loading jQuery? That won't work because noconflict is a method of jQuery. And `jQuery.noConflict();` should cause an error unless some other js file includes jQuery as well. I guess the output of the console.logs are not that compared with the html code you posted because $j could not be anything (calling noconflict on undefined). Do you want to solve this problem or not? Could you please just put the code back as the original and remove the second time you add jQuery? Then post the exact line where the error occurs? And the output of the logs? – HMR Jul 22 '14 at 10:48
  • Also; highcharts seems to depend on jQuery so why add this before jQuery? If something depends on something else you should add it after the thing it depends on. Add prototype.js later; after jQuery.noConflict as you had in your original post. – HMR Jul 22 '14 at 10:51
  • All errors gone, it worked. thanks a lot HMR!! – Pravin Jul 22 '14 at 11:56
  • That's good. I know it's frustrating trying to figure out why things don't work. – HMR Jul 22 '14 at 13:04

2 Answers2

1

First; don't add jQuery twice, remove the bottom one. Then; don't use $("something").dateRangeSlider because $ is prototype.js you added to overwrite jQuery $.

Try $j().dataRangeSlider or jQuery.dateRangeSlider.

In Chrome or firefox with firebug installed you can open the developer tools/firebug with F12. In the console tab you can paste JavaScript commands and see their outputs

console.log("$.fn.jquery for version:",$.fn  && $.fn.jquery);
console.log("$.fn.dateRangeSlider:",$.fn && jQuery.fn.dateRangeSlider);
console.log("jQuery.fn for verson:",jQuery.fn && jQuery.fn.jquery);
console.log("jQuery.fn dateRangeSlider",jQuery.fn && jQuery.fn.dateRangeSlider);
console.log("$j fn jquery",$j.fn  && $j.fn.jquery);
console.log("$j fn dateRangeSlider:",$j.fn && $j.fn.dateRangeSlider);
HMR
  • 37,593
  • 24
  • 91
  • 160
  • yeah I have used :" $j("#slider").dateRangeSlider({ " in my code and this is where the error is there ( But for another app with same code, it somehow runs) I typed all of the above commands in the console.In 1,2,4 and 6 - both are undefined each time. In 3, "jQuery.fn for verson: 1.10.2" and undefined is output. In 5," $j fn jquery 1.10.2 " and undefined are outputs. Now, mainly we can see that daterangeslider is not being accessed here. why is this? – Pravin Jul 22 '14 at 08:56
  • Also, when I load the app I get a couple of errors in "bundle-bundle-application-defer.js" with - Uncaught TypeError: undefined is not a function . This again indicates a problem in daterangeslider being loaded I think. Let me know your opinions – Pravin Jul 22 '14 at 08:58
  • Updated question, pls check. Same error with highcharts now, what can I do now to resolve this? – Pravin Jul 22 '14 at 10:22
0

Using index.gsp in the following form helped solve the problem for both daterangeslider and highcharts both.

Thanks a lot HMR, the debugging helped.

Index.gsp :

<g:javascript src="d3.v3.min.js"/>

<g:javascript src="jQuery-ui-1.10.4.custom.js"/>
<g:javascript src="jQDateRangeSlider-min.js"/>
<g:javascript src="jQDateRangeSlider-withRuler-min.js"/>
<g:javascript src="jQRangeSliderLabel.js"/>

<script>
var $j = jQuery.noConflict();
</script>
<link rel="stylesheet" href="${resource(dir: 'css', file: 'iThing.css')}" type="text/css">
<link rel="stylesheet" href="css/iThing.css" type="text/css" /> 
<link rel="stylesheet" href="${resource(dir: 'css', file: 'bootstrap.min.css')}" type="text/css">
<link rel="stylesheet" href="${resource(dir: 'css', file: 'dc.css')}" type="text/css">
<style type="text/css"></style>
<g:javascript src="prototype.js"/>
<g:javascript src="highcharts.js"/>
<g:javascript src="exporting.js"/>
Pravin
  • 461
  • 5
  • 26