CActiveForm->error - inputID doesn't work for AJAX Validation

Some of the AJAX validation on my site isn’t working, and I was able to trace the problem back to the validation not having the right ID for the field. Specifically, it’s not working on pages where I’ve had to override the IDs of input elements as the forms of multiple items of the same type are on the same page. I have set inputID in the error $htmlOptions, but have found that this is not working. I traced the problem to the error function in CActiveForm. An excerpt:


$inputID=isset($htmlOptions['inputID']) ? $htmlOptions['inputID'] : $id;







Then, in the javascript, this ‘id’ is used to determine if there is an error.

var hasError = messages!=null && $.isArray(messages[]) && messages[].length>0;

Shouldn’t it be possible to override the $id value? Isn’t the inputID value included for precisely this purpose? I have a workaround, I extended ActiveForm with the following function which makes inputID override id. Any ideas? My override function:

public function error($model, $attribute, $htmlOptions = array(), $enableAjaxValidation = true, $enableClientValidation = true) {

   $html = parent::error($model, $attribute, $htmlOptions, $enableAjaxValidation, $enableClientValidation);

   if($enableAjaxValidation && isset($htmlOptions['inputID'])) {

      $this->attributes[$htmlOptions['inputID']]['id'] = $htmlOptions['inputID'];


   return $html;


Would this be classed as a bug? Does this fix break anything else? Certainly, the fact that you can’t override the ID that the validation uses severely limits your options when it comes to input IDs.

You need to set the ID on the input field and the inpudID on the error call. Can you post all your code for one field?