Requirements ¶
Yii 1.1.1 ~ Yii 1.1.6 This feature has been integrated since version 1.1.7. See CActiveForm
Description: ¶
This extension just extend from {link: CActiveForm} using few codes, it enhances the ajax validation.
- Submit a list of changed attributes to php backend, then can access the attributes list in Controller via $_POST['attributes']['ModelName'] and verify these attributes only.
- First to do client-side javascript validations before submission of ajax, and js validators converted from {link: CValidator} automatically.
Usage: ¶
Using this extension is same as original CActiveForm.
$form = $this->beginWidget('ext.EActiveForm');
...
// as same as normal CActiveForm codes
...
$this->endWidget();
Controller example codes for verifying modified attributes only:
protected function performAjaxValidation($model)
{
if (Yii::app()->request->isAjaxRequest && isset($_POST['ajax']))
{
$class = get_class($model);
if (isset($_POST['attributes']) && is_array($_POST['attributes'][$class]))
$attributes = $_POST['attributes'][$class];
else
$attributes = null;
echo CActiveForm::validate($model, $attributes);
Yii::app()->end();
}
}
ChangeLog: ¶
Nov 28, 2010
- New version number 1.2
- Enable ajax validation bye default(Override the property enableAjaxValidation)
- Fixed issue on radiolist (thanks to ianare's report)
- Fixed issue on incorrectly update error message for attributes when validate on submit.
Nov 14, 2010
- New version number 1.1
- Strict inspection validator is completely converted.
- Add CTypeValidator support
NOTE: ¶
For CRegualarExpressionValidator, please make sure Javascript compatible.
Reporting Issue: ¶
Reporting Issues and comments are welcome, plz report them to offical extension page of Yii. Report issue
Supported Validators
'CRequiredValidator','CRegularExpressionValidator',
'CEmailValidator','CUrlValidator','CCompareValidator',
'CStringValidator','CRangeValidator','CNumberValidator',
'CBooleanValidator'
Great! thanks
This is just great ! Thanks a lot.
I added
public function init(){ $this->enableAjaxValidation = true; $this->clientOptions['validateOnSubmit'] = true; }
because only reason i change Yii generated code to EActiveForm is js validation and it needs the options.
to hung5s
I think it will be better to set the default value of public property enableAjaxValidation true, as follow:
class EActiveForm extends CACtiveForm { public $enableAjaxValidation = true; public $attributesVar = 'attributes'; }
Problem with radiolists
Great extension, a real time saver and takes a load off the server ;-)
One problem though : it will not properly validate radiolist items. This is because it will not look for the value in the 'name' attribute but in 'id', which isn't identical to id for the case of radio lists.
Thanks
to ianare
thanks for your report, I have fixed it. Because I just used validateOnChange, so I haven't found this problem before.
The feature has been integrated since version 1.1.7
As the title, thanks to Qiang.
The extension now only need for the Yii older than version 1.1.7
1.2.tgz corrupt
Your 1.2.tgz is corrupt, but the .zip file is OK.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.