Spam
Spam

Reputation: 179

yii2 Pjax + java script prompt

It there any way to make 'data-confirm' => Please enter the number' not just confirm but some like JS prompt and get imputed values to sent it to controller?

 <?php \yii\widgets\Pjax::begin(['id' => 'pjax-orders_table','clientOptions' => ['method' => 'POST'], 'enablePushState'=>false]) ?>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'id'=>'orders_table',
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            ///some columns

            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{update} {delete}{some}',
                'buttons' => [

                    'some' => function ($url,$model,$key) {
                        if($model->status=='not confirm')
                        {
                            return Html::a('<span class="glyphicon glyphicon-trash"</span>',['my/some', 'id' => $model->id],[
                                'title' => Yii::t('yii', 'Delete'),
                                'data-confirm' => Please enter the number',
                                'data-method' => 'post',

                            ]);
                        }

                    },
                ],
            ],
        ],
    ]); ?>
    <?php \yii\widgets\Pjax::end() ?>

In controller

public actionSome()
{ $dataProvider = new ActiveDataProvider();
            $dataProvider->query = Orders::find()->all();
return $this->render('some',['dataProvider'=>$dataProvider]);
}

Upvotes: 0

Views: 555

Answers (1)

DespeiL
DespeiL

Reputation: 1033

instead of Html::a() use Html::button()where button id = some_item_id and then write this JS code

 $('.buttons_class').click(function(){
            var selection;
            do{
                selection = parseInt(window.prompt("Please enter a number from 1 to 100", ""), 10);
            }
            while(isNaN(selection));
            if(!isNaN(selection))
            {
                $.post("some",{id:45,prompt_value:selection}, function(response)
                {
                    console.log(response);
                    $.pjax.reload({container:'#pjax-orders_table'});
                });
            }
            })

Upvotes: 2

Related Questions