Spinner.php 1.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\jui;

use yii\helpers\Html;

/**
 * Spinner renders an spinner jQuery UI widget.
 *
 * For example:
 *
 * ```php
Alexander Makarov committed
18
 * echo Spinner::widget([
19 20
 *     'model' => $model,
 *     'attribute' => 'country',
Alexander Makarov committed
21 22
 *     'clientOptions' => ['step' => 2],
 * ]);
23 24 25 26 27
 * ```
 *
 * The following example will use the name property instead:
 *
 * ```php
Alexander Makarov committed
28
 * echo Spinner::widget([
29
 *     'name'  => 'country',
Alexander Makarov committed
30 31
 *     'clientOptions' => ['step' => 2],
 * ]);
32
 * ```
33 34 35 36 37 38 39
 *
 * @see http://api.jqueryui.com/spinner/
 * @author Alexander Kochetov <creocoder@gmail.com>
 * @since 2.0
 */
class Spinner extends InputWidget
{
40 41 42 43 44 45
    /**
     * @inheritDoc
     */
    protected $clientEventMap = [
        'spin' => 'spin',
    ];
46

47 48 49 50 51 52 53 54
    /**
     * Renders the widget.
     */
    public function run()
    {
        echo $this->renderWidget();
        $this->registerWidget('spinner', SpinnerAsset::className());
    }
55

56 57 58 59 60 61 62 63 64 65 66 67
    /**
     * Renders the Spinner widget.
     * @return string the rendering result.
     */
    public function renderWidget()
    {
        if ($this->hasModel()) {
            return Html::activeTextInput($this->model, $this->attribute, $this->options);
        } else {
            return Html::textInput($this->name, $this->value, $this->options);
        }
    }
68
}