Closed polinwei closed 7 years ago
Hi! In this variant, ajax deletion with custom confirmation is implemented. Look at how I implemented the confirm here:
Connect SweetAlert2 https://github.com/Dominus77/yii2-advanced-start/blob/3ecb9bc88e546392847a989467aeb625d0f092fc/modules/users/views/backend/default/index.php#L9
Js function confirm https://github.com/Dominus77/yii2-advanced-start/blob/3ecb9bc88e546392847a989467aeb625d0f092fc/modules/users/views/backend/default/index.php#L21-L64
I got the error message : Not the correct query format!
view: index.php
'approve'=>function($url,$model,$key)
{
$options = json_encode([
'title' => Module::t('module', 'Are you sure?'),
'text' => Module::t('module', 'You won\'t be able to revert this!'),
'confirmButtonText' => Yii::t('app', 'Yes, Approve!'),
'cancelButtonText' => Yii::t('app', 'No, do not Approve!'),
'url' => $url,
]);
return Html::a('<span class="glyphicon glyphicon-check"></span>', '#', [
'title' => Yii::t('app', 'Approve'),
'data' => [
'toggle' => 'tooltip',
'pjax' => 0,
],
'onclick' => "confirm({$options}); return false;",
]);
},
control
public function actionApprove($id)
{
if (Yii::$app->request->isAjax) {
$model = Comment::findOne($id);
if ($model->approve()) //核准
{
return [
'title' => Module::t('module', 'Done!'),
'text' => Module::t('module', 'The comment "{:id}" have been successfully approve.', [':name' => $model->id]),
'type' => 'success',
];
}
}
Yii::$app->session->setFlash('error', Module::t('module', 'Not the correct query format!'));
return $this->redirect(['index']);
}
You did not specify a format in the controller: https://github.com/Dominus77/yii2-advanced-start/blob/3ecb9bc88e546392847a989467aeb625d0f092fc/modules/users/controllers/backend/DefaultController.php#L259
Got it . And How refresh page ? I get the error: TypeError: $.pjax is undefined
Updating the page is started in the function: https://github.com/Dominus77/yii2-advanced-start/blob/3ecb9bc88e546392847a989467aeb625d0f092fc/modules/users/views/backend/default/index.php#L50
Yes!! It works !! Thanks.
I add cust action : approve, the confirmButton always show 'Yes, delete!' , How can I replace it