sem-soft / yii2-ajax-confirm
Submit button widget with ajax asking for confirm displaying
1.0
2018-11-23 12:27 UTC
Requires
- php: >=5.4.0
- ext-ctype: *
- ext-mbstring: *
- lib-pcre: *
- yiisoft/yii2: ~2.0.13
This package is auto-updated.
Last update: 2024-10-24 04:30:45 UTC
README
Install by composer
composer require sem-soft/yii2-ajax-confirm
Or add this code into require section of your composer.json and then call composer update in console
"sem-soft/yii2-ajax-confirm": "~1.0"
Description
Implements the logic of submit button widget with server-side confirmation message or without them. Used when additional data verification is required on the server side, and not just a standard confirmation of the action.
Basic usage
Example of configuration in view:
<?php $form = ActiveForm::begin([ 'id' => 'report_import_form', 'options' => [ 'enctype' => 'multipart/form-data' ], 'enableAjaxValidation' => false, ]); ?> ... <?= $form->errorSummary(($model), [ 'class' => 'alert alert-error' ]); ?> ... <?= SubmitButtonWidget::widget([ 'form' => $form, 'confirmRoute' => ['exists'], 'content' => 'Загрузить', 'options' => [ 'class' => 'btn btn-success btn-block', ] ]);?> <?php ActiveForm::end(); ?>
Example of action for check:
... public function actionExists() { Yii::$app->response->format = Response::FORMAT_JSON; ... $form = new FinanceReportImportForm(); ... if ($existReport = FinanceReport::findOne([ 'field1' => $form->field1, 'field2' => $form->field2 ])) { $question = "Отчет по {$existReport->field1} кварталу {$existReport->field2} отчетного года уже существует и будет перезаписан. Продолжить импорт?"; } else { $question = "Выполнить импорт?"; } ... return [ 'can' => $existReport ? false : true, 'question' => $question ]; } ...