I’m using Yii formbuilder which I think is a great tool. The problem is that ajax-Validation doesn’t work anymore once I set showErrorSummary to true in the CForm config file. Any ideas what I’m doing wrong?
Unfortunately cheered too soon. While testing your proposal showErrorSummary was still set to false. It stopped working again once I set it to true. Any help apprechiated.
Of course, you are right: errors are shown next to the corresponding field. But imagine you got a very large form where an error occurs at its very bottom. In that case a user might fail to notice there was an error (just a question of usability).
Both, ajax validation and errorSummary, go smoothly together when handling a form in the conventional way (without formbuilder). So, I wonder if there is a way to make all these compoments work together.
After a lot of research I still can’t figure out what is going wrong. This is what I found so far:
The moment I set showErrorSummaray to true neither jquery.js nor yiiactiveform.js gets registered anymore. As a result of that ajax validation of course cannot do its work. But even registering these scripts manually doesn’t work.
The array “attributes” in run function of CActiveForm (which is called by CForm as far as I can see) is filled with different values depending on showErrorSummary being turned on or of. But I really can’t find a reason for that.
I’m really getting a bit desperate because I would love to use formbuilder. It saves a lot of code writing and is so easy to administrate (once it works ;o)).
This obviosly prevents rendering errors when showErrorSummary is set to true. I wonder, if there is a sense in that which I don’t get? Could anybody explain if so? Or is it a bug?
This is how I solved this problem:
I created the following class in my components folder.
class FormInputElement extends CFormInputElement {
public function render() {
if($this->type==='hidden')
return $this->renderInput();
$output=array(
'{label}'=>$this->renderLabel(),
'{input}'=>$this->renderInput(),
'{hint}'=>$this->renderHint(),
'{error}'=>$this->renderError(), // this is the line I changed
);
return strtr($this->layout,$output);
}
}