如何在yii2中的删除操作中忽略ajaxValidation?

时间:2018-09-06 14:04:56

标签: ajax validation yii2

我有一个如下的表格

    <?php widgets\Pjax::begin(['id' => 'authors', 'enablePushState' => false]) ?>
    <?php $form = ActiveForm::begin(['id' => $model->formName(),'enableAjaxValidation'=>true,'validationUrl'=>\yii\helpers\Url::toRoute(['paper-author/validation']), 'options' => ['data-pjax' => '']]); ?>
    <?php echo $form->field($model, 'FirstName')->textInput()->input('string', ['placeholder' => Yii::t('app', ' FirstName...')])->label(false) ?>
    <?php echo $form->field($model, 'LastName')->textInput()->input('string', ['placeholder' => Yii::t('app', ' LastName...')])->label(false) ?>   
 <?= Html::submitButton('Save', ['class' => 'btn btn-success', 'id' => 'btn1']) ?>
    $widget = Yii::createObject([
                'class' => 'yii\grid\GridView',
                'dataProvider' => $dataprovider,
                'columns' => [
                    'FirstName',
                    'LastName',
                    [
                        'class' => 'yii\grid\ActionColumn',                         
                    ]
                ],
            ]
        );

echo $widget->run();
<?php $form = ActiveForm::end(); ?>
<?php widgets\Pjax::end() ?>

在我的模型中,我有一些规则:

[['FirstName', 'LastName'],'required']

我的控制器:

 public function actionValidation()
    {
        $model = new PaperAuthor();
        $requestPost = Yii::$app->request->post();
        if (Yii::$app->request->isAjax && $model->load($requestPost)) {
            Yii::$app->response->format = 'json';
            return ActiveForm::validate($model);
        }
    }

 public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        echo Json::encode([
                'success' => true,
                'messages' => [
                    Yii::t('app', 'Successfully Deleted.')
                ],
            ]);
    }

actionCreate运作良好。但是我无法从gridview中删除任何已记录的内容,它会引发验证错误(需要验证)。

我该怎么办? 预先感谢。

0 个答案:

没有答案