Difference between #1 and #2 of
A simple way to get Yii client-side form validation run when submitting by ajax

Revision #2 has been created by nlac on Sep 14, 2014, 5:27:28 PM with the memo:

Replaced the $.yii.fix expression everywhere to yiiFix in the tutorial, so the dependency from jquery.yii.js has been removed.
« previous (#1)

Changes

Title unchanged

A simple way to get Yii client-side form validation run when submitting by ajax

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

validation, ajax form submiting, CActiveForm, Forms

Content changed

A time ago i've met the issue that Yii doesn't run any client-side form validation when submitting the form by CHtml::ajaxSubmitButton. The small javascript below helps to fix it. ### Usage
 
 
1) Register the snippet into the HEAD. Be sure that it is linked after jquery.yii.js is linked
pdate!
 
 
Replaced the $.yii.fix expression everywhere to yiiFix in the tutorial, so the dependency from jquery.yii.js has been removed.
 
 
### Usage
 
 
1) Register the snippet into the HEAD
.

2) Configure your CActiveForm instance like this:
[...]
'clientOptions'=>array(
'validateOnSubmit'=>true,
'afterValidate'=>'js:
$.yii.fFix.ajaxSubmit.afterValidate'
)
...
[...]
echo CHtml::ajaxSubmitButton('Whateverlabel', 'whateverurl', array(
...
'beforeSend'=>'js:
$.yii.fFix.ajaxSubmit.beforeSend("#YOUR_FORM_ID")'
...
);
[...]
```php
;
$.yii.fFix = {
ajaxSubmit : {
beforeSend : function(form) {
return function(xhr,opt) {
form = $(form);
$._data(form[0], "events").submit[0].handler();
[...]
4 1
11 followers
Viewed: 63 874 times
Version: 1.1
Category: Tutorials
Written by: nlac
Last updated by: nlac
Created on: Mar 17, 2013
Last updated: 10 years ago
Update Article

Revisions

View all history