EAjaxValidationMessages loads a jQuery plugin which show the validation error messages and changes the CSS class for the error class. It also contains a function to hide those errors and restore the form to its original state.
Changelog ¶
- 20110916 - 1.1 - summary is shown if it exists.
Requirements ¶
- Yii 1.8.0
- jQuery
Usage ¶
In your AJAX-called action validate like this:
$errors = CActiveForm::validate($model);
if ($errors !== '[]') {
echo $errors;
Yii::app()->end();
}
In your view include the widget:
<?php $this->widget('application.extensions.ajaxvalidationmessages.EAjaxValidationMessages',
array(
'errorCssClass'=>'clsError',
'errorMessageCssClass'=>'clsErrorMessage',
'errorSummaryCssClass'=>'clsErrorSummary')); ?>
In your view, in your AJAX callbacks for ajaxSubmitButtons which validate, call the plugin's methods:
'success'=>"function(html) {
if (html.indexOf('{')==0) {
jQuery('#the-form').ajaxvalidationmessages('show', html);
}
else {
jQuery('#the-form').ajaxvalidationmessages('hide');
}
}",
'error'=>"function(html) {
jQuery('#the-form').ajaxvalidationmessages('hide');
}",
where the-form is the id of your form.
SHA1 Checksums: ¶
- 74eef562a616d68302f1279befeafd3fac45007a ajaxvalidationmessages-1.0.tar.bz2
Resources ¶
- Original thread <- problem to solve discussed here.
- Extension thread <- please comment, report bugs, send kudos or send flames here.
great extension
Would be great if you could make it more customizable. Like, ability to just show error summary or apply css from some other file.
Still a great addition. Thanks
too bad this extension exists...
It's a shame this extension has to exist! I think Yii should do this natively.
Thanks for the work anyway...
Cheers
well done
I could se the json response but would have the additional work developing a widget to handle it.
Thanks to you thatś one hurdle overcame
Error hide Issue
Thanks for your effort,
1- I have several fields, when filling the fields, the last field altered the error remain on it and don't hide!
2- What's your mean from this statement: 20110916 - 1.1 - summary is shown if it exists. How to must ensure that it exist?
Patch for not parsing JSON twice
Get a patch. This patch is useful in the case if an AJAX action in a controller returns not only validation information, but also other information in a JSON object, so that we need to access a part of the object, not the entire JSON string.
Cool extension!
Would be better to show one error message for one field. For example, when I got these errors {"IpRelayForm_ip":["IP cant be empty.","IP is invalid."],"IpRelayForm_rules":["Rules cant be empty."]}
2 error messages are shown for the field "IpRelayForm_ip".
Thanks.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.