Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery UI Slider Uncaught TypeError: Cannot read property 'addClass' of undefined

I've checked all of the questions on SO and I can't seem to find the answer. If I place integers directly into the fields then this works but I want to set the parameters dynamically when I set up my script

I'm running JQuery 1.11.1, JQuery UI stable (1.11.0) and touchpunch. I've debugged and the variables are all present and initialised when this is invoked. I've also tried wrapping in self-executing functions with the same results.

(The slide function can be disregarded)

This throws the exception

EDIT I've just noticed that if I click on the slider the exception is thrown but if I then press the right arrow key no exception is thrown and the amount is populated with the value property. I've pasted console output at the end of the question.

$("#slider").slider({
            value: parseInt(window.settings.principal.minimum),
            min: parseInt(window.settings.principal.minimum),
            max: parseInt(window.settings.principal.maximum),
            step: parseInt(window.settings.principal.increment),
            slide: function(event, ui) {
                $( "#amount" ).val( "$" + $( "#slider").slider( "value"));
            }
        });

However this WILL work

$("#slider").slider({
            value: 500,
            min: 500,
            max: 10000,
            step: 500,
            slide: function(event, ui) {
                $( "#amount" ).val( "$" + $( "#slider").slider( "value"));
            }
        });

Console Output

jQuery("#slider").slider("value"); 
5000
jQuery("#slider").slider("min"); 
Error: no such method 'min' for slider widget instance
jQuery("#slider").slider("minimum"); 
Error: no such method 'minimum' for slider widget instance
jQuery("#slider").slider("max"); 
Error: no such method 'max' for slider widget instance
jQuery("#slider").slider("interval"); 
Error: no such method 'interval' for slider widget instance
jQuery("#slider").slider("step"); 
Error: no such method 'step' for slider widget instance
jQuery("#slider").slider("values"); 
[]
like image 351
LiamRyan Avatar asked Jul 23 '14 22:07

LiamRyan


1 Answers

Give your variables (window.settings.principal.*) another look. I just copied your source code, replaced them with my own, and it worked, so your code seems to be fine. Make sure that they're not only valid numbers, but that they make sense in context.

like image 72
Chris Avatar answered Oct 26 '22 18:10

Chris