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.

Vipul
  • 655
  • 2
  • 6
  • 22

1 Answers1

23

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

Mohan
  • 606
  • 4
  • 11
  • 1
    Yeah it's working, I'm still wondering why false didn't work. It could also be an option. – Vipul Nov 12 '16 at 09:39
  • 1
    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). – johnsnails Aug 28 '18 at 05:18
  • 2
    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: https://www.yiiframework.com/doc/api/2.0/yii-widgets-pjax – johnsnails Aug 28 '18 at 05:20
  • 1
    `'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. – Craig London Apr 03 '19 at 03:24