Skip to content

Commit

Permalink
Merge pull request #2320 from resurtm/fixes-2254
Browse files Browse the repository at this point in the history
Fixes #2254: AJAX and client validation doesn't work with `errorSummary` set to true.
  • Loading branch information
samdark committed Jun 24, 2013
2 parents bce3f26 + 0039fb3 commit c8bbdf3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -114,6 +114,7 @@ Version 1.1.14 work in progress
- Enh #2205: CActiveForm::error() now depends on CHtml::$errorContainerTag (malyshev)
- Enh #2213: Added comment with hint on ajax validaton which may lead to duplicate entries in the database to gii form template (elmig, cebe)
- Enh #2217: Support of the empty option for CHtml::radioButtonList() has been introduced (resurtm)
- Enh #2254: CForm::$showErrors property has been added, it controls whether error elements of the form attributes should be rendered (resurtm)
- Enh #2259: Allow creation of new validators on the fly (gusnips)
- Enh #2275: Added primary log rotation by copy and truncate to CFileLogRoute (bdstevens)
- Enh #2415: Cancel current ajax request before create a new one in CGridView and CListView (gusnips)
Expand Down
21 changes: 21 additions & 0 deletions framework/web/form/CForm.php
Expand Up @@ -57,6 +57,10 @@
* (e.g. 'maxlength') in an input specification are rendered as HTML element attributes
* when the input field is rendered. The {@link buttons} property is configured similarly.
*
* If you're going to use AJAX and/or client form validation with the enabled error summary
* you have to set {@link $showErrors} property to true. Please refer to it's documentation
* for more details.
*
* For more details about configuring form elements, please refer to {@link CFormInputElement}
* and {@link CFormButtonElement}.
*
Expand Down Expand Up @@ -114,6 +118,21 @@ class CForm extends CFormElement implements ArrayAccess
* @var boolean whether to show error summary. Defaults to false.
*/
public $showErrorSummary=false;
/**
* @var boolean|null whether error elements of the form attributes should be rendered. There are three possible
* valid values: null, true and false.
*
* Defaults to null meaning that {@link $showErrorSummary} will be used as value. This is done mainly to keep
* backward compatibility with existing applications. If you want to use error summary with AJAX and/or client
* validation you have to set this property to true (recall that {@link CActiveForm::error()} should be called
* for each attribute that is going to be AJAX and/or client validated).
*
* False value means that the error elements of the form attributes shall not be displayed. True value means that
* the error elements of the form attributes will be rendered.
*
* @since 1.1.14
*/
public $showErrors;
/**
* @var array the configuration used to create the active form widget.
* The widget will be used to render the form tag and the error messages.
Expand Down Expand Up @@ -149,6 +168,8 @@ public function __construct($config,$model=null,$parent=null)
if($parent===null)
$parent=Yii::app()->getController();
parent::__construct($config,$parent);
if($this->showErrors===null)
$this->showErrors=!$this->showErrorSummary;
$this->init();
}

Expand Down
2 changes: 1 addition & 1 deletion framework/web/form/CFormInputElement.php
Expand Up @@ -179,7 +179,7 @@ public function render()
'{label}'=>$this->renderLabel(),
'{input}'=>$this->renderInput(),
'{hint}'=>$this->renderHint(),
'{error}'=>$this->getParent()->showErrorSummary ? '' : $this->renderError(),
'{error}'=>!$this->getParent()->showErrors ? '' : $this->renderError(),
);
return strtr($this->layout,$output);
}
Expand Down

0 comments on commit c8bbdf3

Please sign in to comment.