Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable pjax loading on certain buttons inside Pjax container (Yii2)

Tags:

yii2

pjax

I need to disable pjax inside pjax container on some anchor tags like cancel/ back button. Below is my code:

Pjax::begin(['id' => 'pjax-container-pac-form','timeout' => 10000, 'enablePushState' => false]);
$form = ActiveForm::begin([
'options' => [
    'id' => 'create-pac-form',
    'data-pjax' => true
]
]);
echo Html::a(Yii::t('app','Cancel'), ['/agency'], ['class' => 'btn btn-default', 'id' => 'cancelButton', 'data-pjax' => false]);
ActiveForm::end();
Pjax::end();

I tried to add 'data-pjax' => false on anchor tag but it's not working. Although it's redirecing back to specified url but at first it's trying to hit via ajax and after that it redirects back to the link. I would like to disable ajax here and redirect it back to the url being specified. I can do so by moving the cancel button out of pjax container but I'm looking for some better way of doing it without modifying HTML at all.

like image 890
Vipul Avatar asked Nov 12 '16 09:11

Vipul


1 Answers

Replace 'data-pjax' => false with 'data-pjax' => 0 in anchor tag

like image 90
Mohan Avatar answered Sep 19 '22 22:09

Mohan