You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					67 lines
				
				1.3 KiB
			
		
		
			
		
	
	
					67 lines
				
				1.3 KiB
			| 
											13 years ago
										 | <?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;
 | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * AutoComplete renders an autocomplete jQuery UI widget.
 | ||
|  |  *
 | ||
|  |  * For example:
 | ||
|  |  *
 | ||
|  |  * ```php
 | ||
| 
											12 years ago
										 |  * echo AutoComplete::widget([
 | ||
| 
											13 years ago
										 |  *     'model' => $model,
 | ||
|  |  *     'attribute' => 'country',
 | ||
| 
											12 years ago
										 |  *     'clientOptions' => [
 | ||
|  |  *         'source' => ['USA', 'RUS'],
 | ||
|  |  *     ],
 | ||
|  |  * ]);
 | ||
| 
											13 years ago
										 |  * ```
 | ||
|  |  *
 | ||
|  |  * The following example will use the name property instead:
 | ||
|  |  *
 | ||
|  |  * ```php
 | ||
| 
											12 years ago
										 |  * echo AutoComplete::widget([
 | ||
|  |  *     'name' => 'country',
 | ||
|  |  *     'clientOptions' => [
 | ||
|  |  *         'source' => ['USA', 'RUS'],
 | ||
|  |  *     ],
 | ||
|  |  * ]);
 | ||
| 
											13 years ago
										 |  *```
 | ||
|  |  *
 | ||
|  |  * @see http://api.jqueryui.com/autocomplete/
 | ||
|  |  * @author Alexander Kochetov <creocoder@gmail.com>
 | ||
|  |  * @since 2.0
 | ||
|  |  */
 | ||
| 
											13 years ago
										 | class AutoComplete extends InputWidget
 | ||
| 
											13 years ago
										 | {
 | ||
|  | 	/**
 | ||
|  | 	 * Renders the widget.
 | ||
|  | 	 */
 | ||
|  | 	public function run()
 | ||
|  | 	{
 | ||
| 
											13 years ago
										 | 		echo $this->renderWidget();
 | ||
| 
											12 years ago
										 | 		$this->registerWidget('autocomplete', AutoCompleteAsset::className());
 | ||
| 
											13 years ago
										 | 	}
 | ||
|  | 
 | ||
|  | 	/**
 | ||
| 
											13 years ago
										 | 	 * Renders the AutoComplete widget.
 | ||
| 
											13 years ago
										 | 	 * @return string the rendering result.
 | ||
|  | 	 */
 | ||
| 
											13 years ago
										 | 	public function renderWidget()
 | ||
| 
											13 years ago
										 | 	{
 | ||
| 
											13 years ago
										 | 		if ($this->hasModel()) {
 | ||
| 
											13 years ago
										 | 			return Html::activeTextInput($this->model, $this->attribute, $this->options);
 | ||
|  | 		} else {
 | ||
| 
											13 years ago
										 | 			return Html::textInput($this->name, $this->value, $this->options);
 | ||
| 
											13 years ago
										 | 		}
 | ||
|  | 	}
 | ||
|  | }
 |