Код формы
Код: Выделить всё
<?php Modal::begin([
'id' => 'modal',
'title' => $settings_modal['title'],
'size' => 'modal-xl',
]);
?>
<?php $form = ActiveForm::begin([
'id' => 'form--updateMenu',
'enableAjaxValidation' => true,
'validationUrl' => Yii::$app->urlManager->createUrl('site/menu-validate'),
]); ?>
<div class="row">
<div class="col-md-4">
<?=
$form->field($model, 'short_name')->textInput(['maxlength' => true])
->hint(Yii::t('site', 'short_name_description'))
?>
<?=
$form->field($model, 'full_name')->textInput(['maxlength' => true])
->hint(Yii::t('site', 'full_name_description'))
?>
<?=
$form->field($model, 'url')->textInput(['maxlength' => true])
->hint(Yii::t('site', 'url_description'))
?>
</div>
<div class="col-md-4">
<?=
$form->field($model, 'icon')->textInput(['maxlength' => true])
->hint(Yii::t('site', 'icon_description'))
?>
<?= $form->field($model, 'sort_order')->textInput() ?>
</div>
<div class="col-md-4 d-flex">
<div class="mt-4 mx-auto">
<?= $form->field($model, 'navbar_view', ['template' => "<div class=\"checkbox\">\n{input}
{beginLabel}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n</div>"])->checkbox(['value' => true]) ?>
<?= $form->field($model, 'sidebar_view', ['template' => "<div class=\"checkbox\">\n{input}
{beginLabel}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n</div>"])->checkbox(['value' => true]) ?>
<?= $form->field($model, 'main_view', ['template' => "<div class=\"checkbox\">\n{input}
{beginLabel}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n</div>"])->checkbox(['value' => true]) ?>
<?= $form->field($model, 'status', ['template' => "<div class=\"checkbox\">\n{input}
{beginLabel}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n</div>"])->checkbox(['value' => true]) ?>
</div>
</div>
<div class="col-md-12">
<?=
$form->field($model, 'description')->textarea(['rows' => 5])
->hint(Yii::t('site', 'description_description'))
?>
</div>
</div>
<div class="form-group text-center">
<?= Html::submitButton(Yii::t('app', 'save'), [
'class' => 'btn btn-success',
'data' => [
'type' => 'form--updateMenu',
'art' => 'system-menu-Menu-control',
'id' => $model->id,
],
'name' => 'add-edit-menu-button',
]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php Modal::end();
Код: Выделить всё
public function actionMenuControl($id = null): string
{
if (Yii::$app->request->isAjax) {
if ($id) {
$model_menu = $this->findModelMenu($id);
$settings = [
'title' => Yii::t('site', 'item_menu_update',
['menu_item' => $model_menu->short_name]),
'id_modal' => 'modalEditNotebook',
];
}
return $this->renderAjax('menu/menu_form', [
'model' => $model_menu,
'settings_modal' => $settings
]);
}
throw new NotFoundHttpException('The requested page does not exist.');
}
Код: Выделить всё
public function actionMenuValidate()
{
$model = new Menu();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
\Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
return false;
}
Код: Выделить всё
$this->registerJs(
"
$(document).on('beforeSubmit', '#{$id_form}', function () {
let form = $('#{$id_form}').serialize();
$.ajax({
url: '/ajax/',
type: 'POST',
data: form,
success: function (data) {
console.log(result);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR.responseText);
console.log(textStatus);
console.log(errorThrown);
}
});
return false;
});
"
);