0

我有一个用于创建和编辑某些字段的表单。在提交表单之前,我正在使用 Ajax 验证

 <?php $form=$this->beginWidget('CActiveForm', array(
            'id'=>'candidates-profiles-form',
            'enableAjaxValidation'=>true,
                        'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
        'validateOnChange'=>false,
         'beforeValidate'=>"js:function(form) {         
            if((form.data('submitObject')[0].id ) == 'cancel'){
            alert('cancalclicked');
                this.validateOnSubmit = false;
        this.validateOnChange = false;
        this.beforeValidate = ''; // the problem is caused by this line
        form.submit();
        return false;

                }
                else{
                  alert('submitclicked');
                return true;

                }

        }",    
        'afterValidate'=>"js:function(form, data, hasError) {
       if(hasError) {
                alert('We have detected some input errors and has not saved your data. Please click Ok to correct them.');
                return false;
            }
            else {          
                if(confirm('We have validated your input and we are ready to save your data. Please click Ok to save or Cancel to return to input.'))
                    return true;
                else
                    return false;
            }
        }",)


)); ?> 

创建后它完美地进入了afterValidate功能并且工作正常。但编辑后它并不是全部都进入afterValidate。但它进入 beforeValidate 并提交表单而没有到达 afterValidate 。

4

1 回答 1

0

确保你有 $this->performAjaxValidation($model); 在您的控制器中执行该操作。

于 2012-09-18T15:12:43.063 回答