W
W
walder2018-08-31 15:01:53
Yii
walder, 2018-08-31 15:01:53

How to display a modal window on a condition?

Hello,
I have a GridView which has a column with a status, it is editable. How to make a modal window appear when a certain status is selected, for example, I select the "canceled" status, and immediately pop up with options for what reason and the confirm button ...

[
    'class'=>'kartik\grid\EditableColumn',
    'attribute' => 'State',
    'headerOptions' => [
        'style'=>'width: 10%',
    ],
    'editableOptions' => [
        'header'=>'State',
        'inputType'=>\kartik\editable\Editable::INPUT_DROPDOWN_LIST,
        'data'=>Orders::getOrdersStati(),
        'options' => ['class'=>'form-control', 'prompt'=>'Статус...'],
    ],
],

Controller
public function actionIndex()
{
    $searchModel = new Orders();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

    if (isset($_POST['hasEditable']))
    {
        \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

        $model = new Orders();
        $stateId = YII::$app->request->post('editableKey');
        $model = Orders::findOne($stateId);

        $post = [];
        $posted = current($_POST['Orders']);
        $post['Orders'] = $posted;

        if ($model->load($post))
        {
            if($model->save())
            {
                if (isset($posted['State']))
                {
                    $output = $model -> State;
                }
                $out = Json::encode(['output'=>$output, 'message'=>'']);
            }
        }
        echo $out;
        die;
    }

    return $this->render('index', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
    ]);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-09-03
@walder

How to display a modal window on a condition?

This is pure js (jquery), we listen to the event, check what is needed and display it or not. Back (php and yii) has nothing to do with it at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question