mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-16 22:39:52 +08:00
Apply latest feedback
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
namespace yii\bootstrap;
|
namespace yii\bootstrap;
|
||||||
|
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\base\InvalidConfigException;
|
||||||
use yii\base\Model;
|
use yii\base\Model;
|
||||||
use yii\helpers\Html;
|
use yii\helpers\Html;
|
||||||
|
|
||||||
@@ -52,11 +53,15 @@ class TypeAhead extends Widget
|
|||||||
* @var string the model attribute that this field is associated with
|
* @var string the model attribute that this field is associated with
|
||||||
*/
|
*/
|
||||||
public $attribute;
|
public $attribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string the input name. This must be set if [[form]] is not set.
|
* @var string the input name. This must be set if [[form]] is not set.
|
||||||
*/
|
*/
|
||||||
public $name;
|
public $name;
|
||||||
|
/**
|
||||||
|
* @var string the input value.
|
||||||
|
*/
|
||||||
|
public $value;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the widget
|
* Renders the widget
|
||||||
@@ -72,20 +77,20 @@ class TypeAhead extends Widget
|
|||||||
* If [[model]] is null or not from an [[Model]] instance, then the field will be rendered according to
|
* If [[model]] is null or not from an [[Model]] instance, then the field will be rendered according to
|
||||||
* the [[name]] attribute.
|
* the [[name]] attribute.
|
||||||
* @return string the rendering result
|
* @return string the rendering result
|
||||||
* @throws InvalidParamException when none of the required attributes are set to render the textInput. That is,
|
* @throws InvalidConfigException when none of the required attributes are set to render the textInput. That is,
|
||||||
* if [[model]] and [[attribute]] are not set, then [[name]] is required.
|
* if [[model]] and [[attribute]] are not set, then [[name]] is required.
|
||||||
*/
|
*/
|
||||||
public function renderField()
|
public function renderField()
|
||||||
{
|
{
|
||||||
if ($this->model instanceof Model && $this->attribute !== null) {
|
if ($this->model instanceof Model && $this->attribute !== null) {
|
||||||
|
|
||||||
$this->options['id'] = $this->id = Html::getInputId($this->model, $this->attribute);
|
$this->options['id'] = Html::getInputId($this->model, $this->attribute);
|
||||||
|
|
||||||
return Html::activeTextInput($this->model, $this->attribute, $this->options);
|
return Html::activeTextInput($this->model, $this->attribute, $this->options);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->name === null) {
|
if ($this->name === null) {
|
||||||
throw new InvalidParamException(
|
throw new InvalidConfigException(
|
||||||
get_class($this) . ' must specify "form", "model" and "attribute" or "name" property values'
|
get_class($this) . ' must specify "form", "model" and "attribute" or "name" property values'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user