Yii Framework Forum: CJuiSliderInput.php - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CJuiSliderInput.php setting fixed range for single handle not supported Rate Topic: -----

#1 User is offline   BertoMartinez 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 16-September 11

Posted 08 October 2011 - 08:55 PM

Hey everybody. Thought you would all be interested in a little fix I came across when I was unable to use the CJuiSlider helper class to properly build a slider with a fixed min/max to show a fill bar for input.


in framework/zii/widgets/jui change lines 111-115 to the following:
if( (string)$this->options['range'] != 'min' && (string)$this->options['range'] != 'max' ) {
   echo CHtml::activeHiddenField($this->model,$this->maxAttribute,$options);
   $attrMax=$this->maxAttribute;
   $this->options['values']=array($this->model->$attribute,$this->model->$attrMax);
}


Tested with the other varieties of slider input and it works fine. Hope it helps.
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,335
  • Joined: 17-January 09
  • Location:Russia

Posted 09 October 2011 - 06:44 PM

What's the problem in the first place? Would you please provide some code to reproduce it?
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

#3 User is offline   BertoMartinez 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 16-September 11

Posted 10 October 2011 - 11:16 AM

View Postsamdark, on 09 October 2011 - 06:44 PM, said:

What's the problem in the first place? Would you please provide some code to reproduce it?


The class, as far I can tell, does not provide a way to set the range min or max which makes the control "fill" to start from the beginning or end. This means the only option was to have a slider with only a handle and not a progressively filled bar. The documentation of the control allows for "range" to not only be set to true/false but also a string of 'min' or 'max' so that the bar can be provided with a fill bar anchored to the max or min. I could not find a way to accomplish this without modifying the provided helper class which I did and am sharing the modification with all of you.

Anyways, I did end up finding a problem with my previous submission. Here is an update to fix it:
starting at line111
if( (string)$this->options['range'] != 'min' && (string)$this->options['range'] != 'max' ) {
	echo CHtml::activeHiddenField($this->model,$this->maxAttribute,$options);
	$attrMax=$this->maxAttribute;
	$this->options['values']=array($this->model->$attribute,$this->model->$attrMax);
} else {
	$this->options['value']=$this->model->$attribute;
}

0

#4 User is offline   BertoMartinez 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 16-September 11

Posted 21 October 2011 - 04:40 PM

I found 1 problem with my quickfix that prevented the single attribute behavior of setting the range to 'min' or 'max' from happening. I added a boolean to flip when it ran through my previously submitted code. This is used on line 144 such that:

$this->options[$this->event]= ($isRange && !$isMinMaxRange) ?
			"js:function(e,ui){ v=ui.values; jQuery('#{$idHidden}').val(v[0]); jQuery('#{$idHidden}_end').val(v[1]); }":
			'js:function(event, ui) { jQuery(\'#'. $idHidden .'\').val(ui.value); }';


Probably a better way to accomplish this, but I like my duct tape.
0

#5 User is offline   beebe 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 03-May 12

Posted 13 June 2012 - 04:13 PM

View PostBertoMartinez, on 21 October 2011 - 04:40 PM, said:

I found 1 problem with my quickfix that prevented the single attribute behavior of setting the range to 'min' or 'max' from happening. I added a boolean to flip when it ran through my previously submitted code. This is used on line 144 such that:

$this->options[$this->event]= ($isRange && !$isMinMaxRange) ?
			"js:function(e,ui){ v=ui.values; jQuery('#{$idHidden}').val(v[0]); jQuery('#{$idHidden}_end').val(v[1]); }":
			'js:function(event, ui) { jQuery(\'#'. $idHidden .'\').val(ui.value); }';


Probably a better way to accomplish this, but I like my duct tape.



Great fix! I was looking at this yesterday and came up with a very similar fix.
0

#6 User is offline   David Walker 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 21-August 12

Posted 24 August 2012 - 07:46 AM

Hi,

I want to have a CJuiSliderInput on my page which has one value, so I don't really need to use a range but I really like the way you can colour the left of the bar using a fixed minimum range of 0.

However I have tried your code fix which works and I now get the coloured bar but the values that are shown on screen and when submitted do not change.

My code is

<div id="coords_2d_y"><?php echo $model->coords_2d_y?></div>
<?php $this->widget('zii.widgets.jui.CJuiSliderInput', array(
'model'=>$model,
'attribute'=>'coords_2d_y',
'maxAttribute'=>'coords_2d_y',
'event'=>'change',
'options'=>array('range'=>'min','min'=>0,'max'=>1024,'slide'=>'js:function(event,ui){$("#coords_2d_y").text(ui.value);}'),));
?>


Any ideas?
0

#7 User is offline   resurtm 

  • Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 83
  • Joined: 19-December 10

Posted 24 August 2012 - 12:54 PM

Note: there is an opened related issue.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users