mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Fixes #14294: Added InputWidget::renderInputHtml()
to move behavior described in InputWidget
class docs to the class itself
This reverts commit b0162d3a48150be2394dbd30147b3019a433b3a2. Closes #14294
This commit is contained in:
@ -71,6 +71,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #11825: User can login by cookie only once when `autoRenewCookie` is set to false (shirase, silverfire)
|
||||
- Bug #13969: Fixed a bug in a `yii\console\controllers\CacheController` when caches defined via a closure were not detected (Kolyunya)
|
||||
- Enh #14061: Added request scope assignments cache to `yii\rbac\DbManager::checkAccess()` to avoid duplicate queries for user assignments (leandrogehlen, cebe, nineinchnick, ryusoft)
|
||||
- Enh #14294: Added `InputWidget::renderInput()` to move behavior described in `InputWidget` class docs to the class itself (cebe)
|
||||
|
||||
|
||||
2.0.12 June 05, 2017
|
||||
|
@ -104,11 +104,7 @@ class Captcha extends InputWidget
|
||||
public function run()
|
||||
{
|
||||
$this->registerClientScript();
|
||||
if ($this->hasModel()) {
|
||||
$input = Html::activeTextInput($this->model, $this->attribute, $this->options);
|
||||
} else {
|
||||
$input = Html::textInput($this->name, $this->value, $this->options);
|
||||
}
|
||||
$input = $this->renderInputHtml('text');
|
||||
$route = $this->captchaAction;
|
||||
if (is_array($route)) {
|
||||
$route['v'] = uniqid();
|
||||
|
@ -16,9 +16,9 @@ use yii\helpers\Html;
|
||||
/**
|
||||
* InputWidget is the base class for widgets that collect user inputs.
|
||||
*
|
||||
* An input widget can be associated with a data model and an attribute,
|
||||
* or a name and a value. If the former, the name and the value will
|
||||
* be generated automatically.
|
||||
* An input widget can be associated with a data [[model]] and an [[attribute]],
|
||||
* or a [[name]] and a [[value]]. If the former, the name and the value will
|
||||
* be generated automatically (subclasses may call [[renderInputHtml()]] to follow this behavior).
|
||||
*
|
||||
* Classes extending from this widget can be used in an [[\yii\widgets\ActiveForm|ActiveForm]]
|
||||
* using the [[\yii\widgets\ActiveField::widget()|widget()]] method, for example like this:
|
||||
@ -87,4 +87,25 @@ class InputWidget extends Widget
|
||||
{
|
||||
return $this->model instanceof Model && $this->attribute !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a HTML input tag
|
||||
*
|
||||
* This will call [[Html::activeInput()]] if the input widget is [[hasModel()|tied to a model]],
|
||||
* or [[Html::input()]] if not.
|
||||
*
|
||||
* @param string $type the type of the input to create.
|
||||
* @return string the HTML of the input field.
|
||||
* @since 2.0.13
|
||||
* @see Html::activeInput()
|
||||
* @see Html::input()
|
||||
*/
|
||||
protected function renderInputHtml($type)
|
||||
{
|
||||
if ($this->hasModel()) {
|
||||
return Html::activeInput($type, $this->model, $this->attribute, $this->options);
|
||||
} else {
|
||||
return Html::input($type, $this->name, $this->value, $this->options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,11 +124,7 @@ class MaskedInput extends InputWidget
|
||||
public function run()
|
||||
{
|
||||
$this->registerClientScript();
|
||||
if ($this->hasModel()) {
|
||||
echo Html::activeInput($this->type, $this->model, $this->attribute, $this->options);
|
||||
} else {
|
||||
echo Html::input($this->type, $this->name, $this->value, $this->options);
|
||||
}
|
||||
echo $this->renderInputHtml($this->type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user