Class yii\jui\SliderInput

Inheritanceyii\jui\SliderInput » yii\jui\InputWidget » yii\jui\Widget » yii\base\Widget
Available since extension's version2.0
Source Code https://github.com/yiisoft/yii2-jui/blob/master/SliderInput.php

SliderInput renders a slider jQuery UI widget that writes its value into hidden input.

For example,

echo SliderInput::widget([
    'model' => $model,
    'attribute' => 'amount',
    'clientOptions' => [
        'min' => 1,
        'max' => 10,
    ],
]);

The following example will use the name property instead:

echo SliderInput::widget([
    'name' => 'amount',
    'clientOptions' => [
        'min' => 1,
        'max' => 10,
    ],
]);

You can also use this widget in an yii\widgets\ActiveForm using the yii\widgets\ActiveField::widget() method, for example like this:

<?= $form->field($model, 'from_date')->widget(\yii\jui\SliderInput::classname(), [
    'clientOptions' => [
        'min' => 1,
        'max' => 10,
    ],
]) ?>

See also http://api.jqueryui.com/slider/.

Public Properties

Hide inherited properties

Property Type Description Defined By
$attribute string The model attribute that this widget is associated with. yii\jui\InputWidget
$clientEventMap array Event names mapped to what should be specified in .on(). yii\jui\SliderInput
$clientEvents array The event handlers for the underlying jQuery UI widget. yii\jui\Widget
$clientOptions array The options for the underlying jQuery UI widget. yii\jui\Widget
$containerOptions array The HTML attributes for the container tag. yii\jui\SliderInput
$model \yii\base\Model The data model that this widget is associated with. yii\jui\InputWidget
$name string The input name. yii\jui\InputWidget
$options array The HTML attributes for the widget container tag. yii\jui\Widget
$value string The input value. yii\jui\InputWidget

Protected Properties

Hide inherited properties

Property Type Description Defined By

Public Methods

Hide inherited methods

Method Description Defined By
init() Initializes the widget. yii\jui\SliderInput
run() Executes the widget. yii\jui\SliderInput

Protected Methods

Hide inherited methods

Method Description Defined By
hasModel() yii\jui\InputWidget
registerClientEvents() Registers a specific jQuery UI widget events yii\jui\Widget
registerClientOptions() Registers a specific jQuery UI widget options yii\jui\Widget
registerWidget() Registers a specific jQuery UI widget asset bundle, initializes it with client options and registers related events yii\jui\Widget

Property Details

Hide inherited properties

$clientEventMap protected property

Event names mapped to what should be specified in .on(). If empty, it is assumed that event passed to clientEvents is prefixed with widget name.

protected array $clientEventMap = [
    
'change' => 'slidechange',
    
'create' => 'slidecreate',
    
'slide' => 'slide',
    
'start' => 'slidestart',
    
'stop' => 'slidestop',
]
$containerOptions public property

The HTML attributes for the container tag.

See also \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.

Method Details

Hide inherited methods

hasModel() protected method
protected boolean hasModel ( )
return boolean

Whether this widget is associated with a data model.

                protected function hasModel()
{
    return $this->model instanceof Model && $this->attribute !== null;
}

            
init() public method

Initializes the widget.

If you override this method, make sure you call the parent implementation first.

public void init ( )

                public function init()
{
    parent::init();
    if (!isset($this->containerOptions['id'])) {
        $this->containerOptions['id'] = $this->options['id'] . '-container';
    }
}

            
registerClientEvents() protected method

Defined in: yii\jui\Widget::registerClientEvents()

Registers a specific jQuery UI widget events

protected void registerClientEvents ( $name, $id )
$name string

The name of the jQuery UI widget

$id string

The ID of the widget

                protected function registerClientEvents($name, $id)
{
    if (!empty($this->clientEvents)) {
        $js = [];
        foreach ($this->clientEvents as $event => $handler) {
            if (isset($this->clientEventMap[$event])) {
                $eventName = $this->clientEventMap[$event];
            } else {
                $eventName = strtolower($name . $event);
            }
            $js[] = "jQuery('#$id').on('$eventName', $handler);";
        }
        $this->getView()->registerJs(implode("\n", $js));
    }
}

            
registerClientOptions() protected method

Defined in: yii\jui\Widget::registerClientOptions()

Registers a specific jQuery UI widget options

protected void registerClientOptions ( $name, $id )
$name string

The name of the jQuery UI widget

$id string

The ID of the widget

                protected function registerClientOptions($name, $id)
{
    if ($this->clientOptions !== false) {
        $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
        $js = "jQuery('#$id').$name($options);";
        $this->getView()->registerJs($js);
    }
}

            
registerWidget() protected method

Defined in: yii\jui\Widget::registerWidget()

Registers a specific jQuery UI widget asset bundle, initializes it with client options and registers related events

protected void registerWidget ( $name, $id null )
$name string

The name of the jQuery UI widget

$id string

The ID of the widget. If null, it will use the id value of $options.

                protected function registerWidget($name, $id = null)
{
    if ($id === null) {
        $id = $this->options['id'];
    }
    JuiAsset::register($this->getView());
    $this->registerClientEvents($name, $id);
    $this->registerClientOptions($name, $id);
}

            
run() public method

Executes the widget.

public void run ( )

                public function run()
{
    echo Html::tag('div', '', $this->containerOptions);
    if ($this->hasModel()) {
        echo Html::activeHiddenInput($this->model, $this->attribute, $this->options);
        $this->clientOptions['value'] = Html::getAttributeValue($this->model, $this->attribute);
    } else {
        echo Html::hiddenInput($this->name, $this->value, $this->options);
        $this->clientOptions['value'] = $this->value;
    }
    if (!isset($this->clientEvents['slide'])) {
        $this->clientEvents['slide'] = 'function (event, ui) {
            jQuery("#' . $this->options['id'] . '").val(ui.value);
        }';
    }
    $this->registerWidget('slider', $this->containerOptions['id']);
}