Reputation: 671
I am trying to submit the form via pjax and after submission I want to refresh the table but after submitting the form and trying to reload ( $.pjax.reload({container:'#products-table'});
) the jquery scripts are not working anymore. Even I added pjax:success
but if I don't reload the table, all scripts are working and sending the requests and then I have to reload manually in order to see the changes. Or I have tried to submit form without pjax and the page reloads by Yii and then again proplems with scripts. Please your feedbacks. Thanks
$(document).on('ready pjax:success', function(){
$("form.products-input-style").on('beforeSubmit', function(e){
var form = $(this);
$.ajax({
type : "POST",
url: form.attr('action'),
data: new FormData(this),
processData: false,
contentType: false,
success : function(response) {
$.pjax.reload({container:'#products-table'});
$.notify({
icon: "pe-7s-check",
message: "Product is updated."
},{
type: type[2],
timer: 10,
placement: {
from: 'top',
align: 'right'
}
});
},
error : function(response){
console.log(response);
$.notify({
icon: "pe-7s-close-circle",
message: "Error! " + response
},{
type: type[4],
timer: 10,
placement: {
from: 'top',
align: 'right'
}
});
}
});
return false;
}).on('submit', function(e){
e.preventDefault();
});
});
Upvotes: 1
Views: 3030
Reputation: 2041
I think your handler will replaced by new html code (after Pjax update). Try to use delegated handlers.
For example:
$(function(){
$(document).on('beforeSubmit', 'form.products-input-style', function(event){
// ...
}
});
Upvotes: 0
Reputation: 381
If You have problem with input forms after pjax reload then, try to disable yii client side validation:
ActiveForm::begin([
'enableClientScript' => false,
]);
This is some bug on yii\widgets\ActiveForm and yii\bootstrap\ActiveForm.
Upvotes: 0