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

1

12

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.

Tented answered 12/11, 2016 at 9:23 Comment(0)
L
23

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

Lesterlesya answered 12/11, 2016 at 9:26 Comment(4)
Yeah it's working, I'm still wondering why false didn't work. It could also be an option.Tented
I am sure 'data' => ['pjax' => false] use to work, but I was just informed that it had essentially stopped working (I did a recent composer update which might be related).Elongation
Just to confirm, official documentation does say to do the following: You may disable pjax for a specific link inside the container by adding data-pjax="0" attribute to this link.. Reference: yiiframework.com/doc/api/2.0/yii-widgets-pjaxElongation
'data-pjax' => false doesn't work because it is telling the widget that this attribute isn't needed. 'data-pjax' => 0 works because it tells the widget that you want that attribute and its value to be 0. Granted, it's not very intuitive because adding 'data-pjax' => true will render data-pjax on the input.Beatriz

© 2022 - 2024 — McMap. All rights reserved.