Open jeffrobdun opened 9 years ago
I have the same problem. I have the following slider in my form:
$form->field($job, 'rate')->widget(Slider::classname(), [
'pluginOptions'=>[
'min'=>0,
'max'=>100,
'step'=>1,
'ticks' => [0, 25, 50, 75, 100],
'ticks_positions' => [0, 25, 50, 75, 100],
'ticks_labels' => [0, 25, 50, 75, 100],
'tooltip'=>'always',
]
])->label(false))
If I save it with 0 value, then by next edit the slider is positioned at 5.
The problem is probably in the bootstrap-slider: https://github.com/seiyria/bootstrap-slider
I have changed the default value to 0 in my fork. It works, but it is not a general solution of the problem. See: https://github.com/AntoninSlejska/yii2-slider/commit/58dade83f94ba80e9b07e4147e4a282bf082f3f5
This was my solution to this problem:
<?= $form->field($searchModel, 'totalRange')->widget(Slider::class, [
// Check model for set value, otherwise use default
'options' => ['value' => empty($searchModel->totalRange) ? '0,100' : $searchModel->totalRange],
'pluginOptions'=>[
'min' => 0,
// Set the maximum dynamic to the maximum value of the model, but with a lower bound
'max' => ($t = (int) $searchModel->getTotalMax()) > 100 ? $t : 100,
'range' => true,
'step' => 1,
'handle' => 'square',
'tooltip' => 'always'
]]);
?>
I have this slider:
Slider::widget([ 'name'=>'currentValue', 'id'=>'currentValue', 'value'=> $currentValueTotal, 'sliderColor'=>Slider::TYPE_GREY, 'handleColor'=>"#66BB6A", 'pluginOptions'=>[ 'handle'=>'round', 'min' => 0, 'max' => (($currentValueTotal > 0) ? $currentValueTotal + 15000 : 1000000), 'step' => 10 ] ])
If the value is set to zero the slider will instead load with the value of 5. Can you fix this please?
This was also mentioned by another user in the comments of your demo. http://demos.krajee.com/slider#comment-2020068029
Thanks for your help