loveorigami / yii2-modal-ajax

A wrapper around Yii2 Bootstrap Modal for using an ActiveForm via AJAX inside.
MIT License
50 stars 29 forks source link

open modal only first attempt #3

Closed paskuale75 closed 7 years ago

paskuale75 commented 7 years ago

Hi @loveorigami why after close the modal, if I reopen it, show me only the header ?

Thanks

loveorigami commented 7 years ago

How you use? I am not have this problem.

paskuale75 commented 7 years ago

At first click on button all works, from second ... it call twice the get url ... and I see only the modal header...

paskuale75 commented 7 years ago

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,
            ]);
        }
    }
paskuale75 commented 7 years ago

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',
        ]);
paskuale75 commented 7 years ago

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}'
        ],
loveorigami commented 7 years ago

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.

loveorigami commented 7 years ago

May be your form have widgets with included js? (datapicker, TinyMce....). Make easy form with inputs and try it.

paskuale75 commented 7 years ago

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 :(

paskuale75 commented 7 years ago

With easy form (yii\widgets\ActiveForm) ... don't solve. I've only a yii\jui\AutoComplete in it.

I removed autocomplete too, same issue.

loveorigami commented 7 years ago

Can you try without kartik grid? I use with standart grid and no problem with second click.

paskuale75 commented 7 years ago

I try with other vendor/gridView don't solve .... :(

loveorigami commented 7 years ago

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
])
paskuale75 commented 7 years ago

I tried as you suggested, but it did not work :'(

loveorigami commented 7 years ago

Try without kartik grid