ajaxvalidationmessages

Shows validation messages coming from an AJAX-called action.
8 followers

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

Total 4 comments

#12816 report it
msoa at 2013/04/13 09:08am
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?

#8195 report it
Victor Silver at 2012/05/16 09:25am
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

#6122 report it
fleuryc at 2011/12/14 09:29am
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

#5119 report it
Mukesh at 2011/09/15 11:07am
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

Leave a comment

Please to leave your comment.

Create extension