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

namespace yii\jui;

use Yii;
use yii\helpers\Html;

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

45 46 47 48 49 50
	/**
	 * Renders the widget.
	 */
	public function run()
	{
		echo $this->renderWidget();
Qiang Xue committed
51
		$this->registerWidget('spinner', SpinnerAsset::className());
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
	}

	/**
	 * 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);
		}
	}
}