kartik-v / yii2-slider

A slider input with orientations, range selections and more features based on bootstrap-slider.
http://demos.krajee.com/slider
Other
28 stars 20 forks source link

Slider setting value to five instead of zero when value is set to zero #16

Open jeffrobdun opened 9 years ago

jeffrobdun commented 9 years ago

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

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/26487315-slider-setting-value-to-five-instead-of-zero-when-value-is-set-to-zero?utm_campaign=plugin&utm_content=tracker%2F2315488&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F2315488&utm_medium=issues&utm_source=github).
AntoninSlejska commented 8 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.

AntoninSlejska commented 8 years ago

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

PaulVanSchayck commented 3 years ago

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'
  ]]); 
?>