Commit 8ac79a35 by Qiang Xue

support hiding error and label tags via error(false) and label(false).

parent b5f351b6
...@@ -226,7 +226,8 @@ class ActiveField extends Component ...@@ -226,7 +226,8 @@ class ActiveField extends Component
/** /**
* Generates a label tag for [[attribute]]. * Generates a label tag for [[attribute]].
* @param string $label the label to use. If null, it will be generated via [[Model::getAttributeLabel()]]. * @param string|boolean $label the label to use. If null, the label will be generated via [[Model::getAttributeLabel()]].
* If false, the generated field will not contain the label part.
* Note that this will NOT be [[Html::encode()|encoded]]. * Note that this will NOT be [[Html::encode()|encoded]].
* @param array $options the tag options in terms of name-value pairs. It will be merged with [[labelOptions]]. * @param array $options the tag options in terms of name-value pairs. It will be merged with [[labelOptions]].
* The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded * The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded
...@@ -235,6 +236,11 @@ class ActiveField extends Component ...@@ -235,6 +236,11 @@ class ActiveField extends Component
*/ */
public function label($label = null, $options = []) public function label($label = null, $options = [])
{ {
if ($label === false) {
$this->parts['{label}'] = '';
return $this;
}
$options = array_merge($this->labelOptions, $options); $options = array_merge($this->labelOptions, $options);
if ($label !== null) { if ($label !== null) {
$options['label'] = $label; $options['label'] = $label;
...@@ -247,7 +253,7 @@ class ActiveField extends Component ...@@ -247,7 +253,7 @@ class ActiveField extends Component
/** /**
* Generates a tag that contains the first validation error of [[attribute]]. * Generates a tag that contains the first validation error of [[attribute]].
* Note that even if there is no validation error, this method will still return an empty error tag. * 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]]. * @param array|boolean $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 * The options will be rendered as the attributes of the resulting tag. The values will be HTML-encoded
* using [[Html::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.
* *
...@@ -255,10 +261,16 @@ class ActiveField extends Component ...@@ -255,10 +261,16 @@ class ActiveField extends Component
* *
* - tag: this specifies the tag name. If not set, "div" will be used. * - tag: this specifies the tag name. If not set, "div" will be used.
* *
* If this parameter is false, no error tag will be rendered.
*
* @return static the field object itself * @return static the field object itself
*/ */
public function error($options = []) public function error($options = [])
{ {
if ($options === false) {
$this->parts['{error}'] = '';
return $this;
}
$options = array_merge($this->errorOptions, $options); $options = array_merge($this->errorOptions, $options);
$this->parts['{error}'] = Html::error($this->model, $this->attribute, $options); $this->parts['{error}'] = Html::error($this->model, $this->attribute, $options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment