I.e. I only want errorSummary to display errors for enquiry model. However what is happening is that the errors for user model are also being displayed. I have validateOnSubmit option enabled.
For example here is one of my ‘user’ fields on the form:
Your mistaken <?php echo $form->errorSummary($enquiry); ?> has nothing to do with the AJAX request. It does however generate a hidden div to populate via Javascript.
<div id="user-form_es_" class="errorSummary" style="display:none"><p>Please fix the following input errors:</p>
<ul><li>dummy</li></ul></div>
Which depending on the clientOptions might get used.
If you inspect the AJAX response you should see a JSON object e.g.
{"User_email":["Email cannot be blank."],"User_new_password":["Password cannot be blank."],"User_new_password_confirmation":["Password Confirmation cannot be blank."],"User_role":["Role cannot be blank."]}
which will be generated by the echo CActiveForm::validate(array($enquiry, $user)); method (obviously with different error messages).
This then gets used by the jquery activeform plugin (look in jquery.yiiactiveform.js) to display the error messages, I think there is a "updateSummary" method in there (had a look at it a while back). This method then tagets some hidden divs to show the error message/s e.g. <div id="User_email_em_" class="errorMessage" style="display:none"></div> which get generated when you enable ajax validation!
Thats the first time you have metioned having validateOnSubmit enabled, which might behave differently I think! well I hope its useful to someone else…if not you.
I think if you disable AJAX it should give you the desired effect.
The errorSummary method only creates a placeholder div for the AJAX request to work with, it does nothing else! that is unless AJAX is off, only then does it show error messages for the models you pass to it.
When AJAX is enabled, the div gets populated via the "updateSummary" callback which occurs after the AJAX request (look in jquery.yiiactiveform.js).
This array of models are used for display errors in post methods, but when you are using ajax validation, it is not making any distinction.
From this point of view, is an unexpected behavior (or a bug). Possible fix can be to change the ajax validation response in order to add the name of the model, for example, and to use this name for filter the errors in the js function that fill the error summary.
Right now:
there is no such an id
ther is no possiblity to add the filter (the function beforeValidat runs before the validation is submitted, and the afterValidat after all errors are already displaied).
We could use the the afterValidate if the <li> of the error summary were create with an id/class or some other way to recognize the model generate this error, but this is also not possible, they are plane li.
I don’t see any option, expect inspecthing the code of CActiveForm and extend it.
This way you do the validation of user but you do not output the errors, and validate the enquiry model and output possible errors only for this model…