mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-27 12:33:09 +08:00
Merge remote-tracking branch 'upstream/master' into add-tests
This commit is contained in:
@@ -314,11 +314,7 @@ class Formatter extends Component
|
||||
protected function normalizeDatetimeValue($value)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
if (ctype_digit($value) || $value[0] === '-' && ctype_digit(substr($value, 1))) {
|
||||
return (int)$value;
|
||||
} else {
|
||||
return strtotime($value);
|
||||
}
|
||||
return is_numeric($value) ? (int)$value : strtotime($value);
|
||||
} elseif ($value instanceof DateTime) {
|
||||
return $value->getTimestamp();
|
||||
} else {
|
||||
|
||||
@@ -21,8 +21,9 @@ use yii\helpers\Html;
|
||||
class Dropdown extends Widget
|
||||
{
|
||||
/**
|
||||
* @var array list of menu items in the dropdown. Each array element represents a single
|
||||
* menu with the following structure:
|
||||
* @var array list of menu items in the dropdown. Each array element can be either an HTML string,
|
||||
* or an array representing a single menu with the following structure:
|
||||
*
|
||||
* - label: string, required, the label of the item link
|
||||
* - url: string, optional, the url of the item link. Defaults to "#".
|
||||
* - linkOptions: array, optional, the HTML attributes of the item link.
|
||||
|
||||
@@ -934,6 +934,30 @@ class HtmlBase
|
||||
return static::label($label, $for, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a tag that contains the first validation error of the specified model attribute.
|
||||
* Note that even if there is no validation error, this method will still return an empty error tag.
|
||||
* @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. The values will be HTML-encoded
|
||||
* using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
|
||||
*
|
||||
* The following options are specially handled:
|
||||
*
|
||||
* - tag: this specifies the tag name. If not set, "p" will be used.
|
||||
*
|
||||
* @return string the generated label tag
|
||||
*/
|
||||
public static function error($model, $attribute, $options = array())
|
||||
{
|
||||
$attribute = static::getAttributeName($attribute);
|
||||
$error = $model->getFirstError($attribute);
|
||||
$tag = isset($options['tag']) ? $options['tag'] : 'p';
|
||||
unset($options['tag']);
|
||||
return Html::tag($tag, Html::encode($error), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an input tag for the given model attribute.
|
||||
* This method will generate the "name" and "value" tag attributes automatically for the model attribute
|
||||
|
||||
@@ -146,7 +146,6 @@ class ActiveField extends Component
|
||||
protected function getClientOptions()
|
||||
{
|
||||
$enableClientValidation = $this->enableClientValidation || $this->enableClientValidation === null && $this->form->enableClientValidation;
|
||||
$enableAjaxValidation = $this->enableAjaxValidation || $this->enableAjaxValidation === null && $this->form->enableAjaxValidation;
|
||||
if ($enableClientValidation) {
|
||||
$attribute = Html::getAttributeName($this->attribute);
|
||||
$validators = array();
|
||||
@@ -162,6 +161,7 @@ class ActiveField extends Component
|
||||
}
|
||||
}
|
||||
|
||||
$enableAjaxValidation = $this->enableAjaxValidation || $this->enableAjaxValidation === null && $this->form->enableAjaxValidation;
|
||||
if ($enableAjaxValidation) {
|
||||
$options['enableAjaxValidation'] = 1;
|
||||
}
|
||||
@@ -169,12 +169,7 @@ class ActiveField extends Component
|
||||
if ($enableClientValidation && !empty($options['validate']) || $enableAjaxValidation) {
|
||||
$inputID = Html::getInputId($this->model, $this->attribute);
|
||||
$options['name'] = $inputID;
|
||||
$names = array(
|
||||
'validateOnChange',
|
||||
'validateOnType',
|
||||
'validationDelay',
|
||||
);
|
||||
foreach ($names as $name) {
|
||||
foreach (array('validateOnChange', 'validateOnType', 'validationDelay') as $name) {
|
||||
$options[$name] = $this->$name === null ? $this->form->$name : $this->$name;
|
||||
}
|
||||
$options['container'] = isset($this->selectors['container']) ? $this->selectors['container'] : ".field-$inputID";
|
||||
@@ -216,22 +211,18 @@ class ActiveField extends Component
|
||||
* Note that even if there is no validation error, this method will still return an empty error tag.
|
||||
* @param array $options the tag options in terms of name-value pairs. It will be merged with [[errorOptions]].
|
||||
* The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded
|
||||
* using [[encode()]]. If a value is null, the corresponding attribute will not be rendered.
|
||||
* using [[Html::encode()]]. If a value is null, the corresponding attribute will not be rendered.
|
||||
*
|
||||
* The following options are specially handled:
|
||||
*
|
||||
* - tag: this specifies the tag name. If not set, "span" will be used.
|
||||
* - tag: this specifies the tag name. If not set, "p" will be used.
|
||||
*
|
||||
* @return string the generated label tag
|
||||
*/
|
||||
public function error($options = array())
|
||||
{
|
||||
$options = array_merge($this->errorOptions, $options);
|
||||
$attribute = Html::getAttributeName($this->attribute);
|
||||
$error = $this->model->getFirstError($attribute);
|
||||
$tag = isset($options['tag']) ? $options['tag'] : 'span';
|
||||
unset($options['tag']);
|
||||
return Html::tag($tag, Html::encode($error), $options);
|
||||
return Html::error($this->model, $this->attribute, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user