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

Value pluginOptions #1

Closed WaterSpout closed 10 years ago

WaterSpout commented 10 years ago

Здравствуйте. При использование слайдера в GridView некорректно заносится предустановленное значение — value для range:

'columns' => [
 [
                    'attribute'=>'payment',
                    'filterType'=>GridView::FILTER_SLIDER,
                    'filterWidgetOptions'=>[
                        'pluginOptions'=>[
                            'value'=>[5,99],
                            'min'=>1,
                            'max'=>1000,
                            'range'=>true
                        ],
                    ]
 ]
]

Для моего случая помогло комментирование 55-ой строки в yii2-slider / slider / Slider.php

$this->pluginOptions['value'] = (!empty($this->value)) ? $this->value : null;

$this->value — это свойство является пустым, а во всех случаях оно заполняется только после инициализации слайдера, следовательно свойство pluginOptions['value'] перезаписывается на null

kartik-v commented 10 years ago

I do not understand Russian, but I am trying to understand from the context, what you are saying. There is a reason why $this->pluginOptions['value'] must be set to null. If you do not pass a value, the slider will display a wrong initial value - it will display the half point value (e.g. the slider will display 5 when no value is set and when the max is set to 10).

Also, in GridView setting a filter input value to null - should display all values by default. It is what you want anyway. What is the error you are facing?

WaterSpout commented 10 years ago

i'm sorry, for wrong language. I wanted to say, when i try pass a value in pluginOptions slider-range does not work, $this->pluginOptions['value'] always = null since $this->value always = null

kartik-v commented 10 years ago

You should not pass the value in pluginOptions. Instead you should set the value of the source attribute. For example, in your case:

// set a default value or change the condition below to 
// what you need (you can change the $model->search() 
// function as well to achieve this).
if (empty($model->payment)) {
    $model->payment = [5,99]; 
}

// render gridview
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $model,
    'columns' => [
        [
            'attribute'=>'payment',
            'filterType'=>GridView::FILTER_SLIDER,
            'filterWidgetOptions'=>[
                'pluginOptions'=>[
                    'min'=>1,
                    'max'=>1000,
                    'range'=>true
                ],
            ]
        ]
    ]
]);
WaterSpout commented 10 years ago

sorry, hmm, right, but if i try do it, i get this error Array to string conversion

public static function input($type, $name = null, $value = null, $options = [])
    {
        $options['type'] = $type;
        $options['name'] = $name;
        $options['value'] = $value === null ? null : (string) $value; // <-- here
        return static::tag('input', '', $options);
    }
kartik-v commented 10 years ago

Will check and update on this. Meanwhile, you can also pass the value as a string concatenated by ,... e.g. 5,99 will work instead of passing it as an array. In fact will record this as a bug fix and update.

WaterSpout commented 10 years ago

Thanks for your help

kartik-v commented 10 years ago

Extension is upgraded to release v1.1.0.Closed with the latest commit, for range you need to pass the two values together as a string separated with a , (comma). The value is also saved this way by the plugin.

Refer updated documentation and demos.

Wait for 30 minutes and update via composer.