Open loveorigami opened 8 years ago
$('#createCompany').on('kbModalSubmit', function(event, data, status, xhr) { console.log('kbModalSubmit'); // You may call pjax reloads here });
I think, better
$('#createCompany').on('kbModalSubmit', function(event, data, status, xhr) {
console.log('kbModalSubmit');
if (status) {
// You may call pjax reloads here
}
});
and need add line
status = false
in https://github.com/karnbrockgmbh/yii2-modal-ajax/blob/master/assets/js/kb-modal-ajax.js#L160
here my code
<?php
use yii\widgets\Pjax;
$this->registerJs(
"$('#add-author-lib_id').on('kbModalSubmit', function(event, data, status, xhr) {
console.log('kbModalSubmit' + status);
if(status){
$.pjax.reload({container:'#author-create'}); //Reload Form
}
});"
);
?>
<div class="author-create">
<?php Pjax::begin([
'id' => 'author-create',
'timeout' => 100000
]); ?>
<?php echo $this->render('_form', [
'model' => $model
]) ?>
<?php Pjax::end(); ?>
</div>
but after submit in bootstrap - form is not reloaded by pjax (((...
I am did better ) In controller
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,
'id' => $model->id,
'name' => $model->name,
];
}
In view
$('#createCompany').on('kbModalSubmit', function(event, data, status, xhr) {
console.log('kbModalSubmit' + status);
if(status){
$(this).modal('toggle');
$('#createCompany-select').append($('<option></option>').attr('value', data['id']).prop("selected","selected").text(data['name']));
}
});
How update form after formSubmit?