Set Default Values For Range Slider Using Cjuisliderinput

Pretty much exactly as the topic, I can’t set the default values for the range slider. Here’s my code


$form->widget('zii.widgets.jui.CJuiSliderInput', array(

			'model'=>$model,

			'attribute'=>'price_from',

			'maxAttribute'=>'price_to',

			'event'=>'change',

			'value'=>60,

			'options'=>array(

				'range'=>true,

				'min'=>0,

				'max'=>30000,

				'step'=>100,

				'values'=>array(0,30000),

				

				'slide'=>'js:function(event, ui) {

			$("#amount").text("$" + ui.values[0] + " - $" + ui.values[1]);}',

			)));

Your code seems ok, with the exeption of the "value" key, which seems unnecessary when I read the documentation. Please try without it and check if it works.

Yeah that was just one of my attempts to get any default value but both sliders always at 0. I’ve tried using javascript to set the form values and move the sliders but none of that works.

Very strange. If you aready tried setting it using the values option, I can’t think of anything else.

Do you get javascript errors on your browser?

I don’t get any javascript errors during the initialization but when I tried to use jQuery to set the default values on load, I would get an error that said something like “[Object object] has no attribute ‘slider’”;

Please try setting a class with htmlOptions just to be sure your selector is correct.

Ok I added this to initialization


'htmlOptions'=>array(

		'class'=>'priceSlider'),

and this to javascript section


$('.priceSlider').slider('values',0,0);

$('.priceSlider').slider('values',0,30000);

and this is the error


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

I got curious and made some tests here. It seems that the slider will ignore any values passed as initial values unless the values of the model attributes. In your case, price_from and price_to.

You can assign default values on your model and it will work.