Closed paskuale75 closed 7 years ago
How you use? I am not have this problem.
At first click on button all works, from second ... it call twice the get url ... and I see only the modal header...
My controller action here
public function actionCreate($r_paziente_id=false)
{
$model = new CartellaClinica();
/*
* Carico valori di default (obbligatori)
*/
$model->aperta_data = date('Y-m-d');
$model->r_paziente_id = $r_paziente_id;
$model->pazienteAsString = Paziente::find(['id' => $r_paziente_id])->one()->nominativo;
if ($model->load(Yii::$app->request->post())) {
if ($model->save()) {
if (Yii::$app->request->isAjax) {
// JSON response is expected in case of successful save
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return ['success' => true];
}
if($r_paziente_id) {
return $this->redirect(['//paziente/default/view', 'id' => $r_paziente_id]);
}else{
return $this->redirect(['index']);
}
//return $this->redirect(['view', 'id' => $model->id]);
}
}
if (Yii::$app->request->isAjax) {
return $this->renderAjax('create', [
'model' => $model,
]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
view (index.php) here, before the grid
echo ModalAjax::widget([
'id' => 'createCartella',
'selector' => 'a.modalButton', // all buttons in grid view with href attribute
'ajaxSubmit' => true, // Submit the contained form as ajax, true by default
'options' => ['class' => 'header-primary'],
'autoClose' => true,
//'pjaxContainer' => '#cartelle_grid',
]);
view (index.php) grid's toolbar button
'toolbar' => [
[
'content'=>
Html::a('<i class="glyphicon glyphicon-plus"></i>', ['create'], ['class' => 'modalButton btn btn-success'])
.' '.
Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['index'], [
'class' => 'btn btn-default',
'title' => 'Reset griglia'
]),
],
'{export}',
'{toggleData}'
],
You have standart or kartik grid? May be have conflict in js function, kartik js not loaded? In console after second click you have error? In yii debag panel have errors? Second click send Post or Get request? May be after reloaded second click send POST and model not save and your see empty modal...
Need more info with debug data.
You similar example work fine in my standart grid.
May be your form have widgets with included js? (datapicker, TinyMce....). Make easy form with inputs and try it.
1) It's kartik grid 2) In console I haven't error, I've two get request. 3) In debug panel no errors 4) First click send Get 5) Second click send Get (x2)
I try to clear kartik\form\ActiveForm same issue :(
With easy form (yii\widgets\ActiveForm) ... don't solve. I've only a yii\jui\AutoComplete in it.
I removed autocomplete too, same issue.
Can you try without kartik grid? I use with standart grid and no problem with second click.
I try with other vendor/gridView don't solve .... :(
I think - need 'data-pjax' => 0, because with 'data-pjax' => 1 (by default) second click will be reloaded container. Try
Html::a('<i class="glyphicon glyphicon-plus"></i>', ['create'], [
'class' => 'modalButton btn btn-success'
'data-pjax' => 0 // or false
])
I tried as you suggested, but it did not work :'(
Try without kartik grid
Hi @loveorigami why after close the modal, if I reopen it, show me only the header ?
Thanks