mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Enh #15226: Auto generate placeholder from fields
This commit is contained in:
@ -3,7 +3,7 @@ Yii Framework 2 Change Log
|
||||
|
||||
2.0.14 under development
|
||||
------------------------
|
||||
|
||||
- Enh #15226: Auto generate placeholder from fields (vladis84)
|
||||
- Bug #15356: Fixed multiple bugs in `yii\db\Query::getTablesUsedInFrom()` (vladis84, samdark)
|
||||
- Bug #14157: Add support for loading default value `CURRENT_TIMESTAMP` of MySQL `datetime` field (rossoneri)
|
||||
- Bug #15046: Throw an `yii\web\HeadersAlreadySentException` if headers were sent before web response (dmirogin)
|
||||
|
@ -1359,9 +1359,25 @@ class BaseHtml
|
||||
public static function activeTextInput($model, $attribute, $options = [])
|
||||
{
|
||||
self::normalizeMaxLength($model, $attribute, $options);
|
||||
self::activePlaceholder($model, $attribute, $options);
|
||||
return static::activeInput('text', $model, $attribute, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate placeholder from model label.
|
||||
* @param Model $model the model object
|
||||
* @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
|
||||
* about attribute expression.
|
||||
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
|
||||
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
|
||||
*/
|
||||
protected static function activePlaceholder($model, $attribute, &$options = [])
|
||||
{
|
||||
if (isset($options['placeholder']) && $options['placeholder'] === true) {
|
||||
$options['placeholder'] = $model->getAttributeLabel($attribute);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a hidden input tag for the given model attribute.
|
||||
* This method will generate the "name" and "value" tag attributes automatically for the model attribute
|
||||
@ -1458,6 +1474,7 @@ class BaseHtml
|
||||
$options['id'] = static::getInputId($model, $attribute);
|
||||
}
|
||||
self::normalizeMaxLength($model, $attribute, $options);
|
||||
self::activePlaceholder($model, $attribute, $options);
|
||||
return static::textarea($name, $value, $options);
|
||||
}
|
||||
|
||||
|
@ -1579,6 +1579,24 @@ HTML;
|
||||
$actual = Html::activeCheckboxList($model, 'types', ['foo']);
|
||||
$this->assertEqualsWithoutLE($expected, $actual);
|
||||
}
|
||||
|
||||
public function testActiveTextInput_placeholderFillFromModel()
|
||||
{
|
||||
$model = new HtmlTestModel();
|
||||
|
||||
$html = Html::activeTextInput($model, 'name', ['placeholder' => true]);
|
||||
|
||||
$this->assertContains('placeholder="Name"', $html);
|
||||
}
|
||||
|
||||
public function testActiveTextInput_customPlaceholder()
|
||||
{
|
||||
$model = new HtmlTestModel();
|
||||
|
||||
$html = Html::activeTextInput($model, 'name', ['placeholder' => 'Custom placeholder']);
|
||||
|
||||
$this->assertContains('placeholder="Custom placeholder"', $html);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user