So for some odd reason, I can’t get Pjax to work with ActiveForm on the submit button.
If I change the submit button to a simple link, then no problem, but of course, the form doesn’t get submitted. Using the submit button, the pjax doesn’t trigger and I get this following error in the console.
Uncaught $.fn.pjax or $.pjax.click requires an anchor element
I believe your error message revolves around trying to use linkSelector to select a button(ie it is not a link) to trigger the Pjax form submit. This means the Pjax will not submit the form because it is looking for a link that does not exist. Try removing that part from your code, and I think your form will start to submit with Pjax if you change the forms data-pjax attribute to be true.
[b]
[/b]
<?php
// remove LinkSelector to stop looking for non existent link to trigger Pjax
Pjax::begin(['enablePushState' => false])
?>
<div class="new-line">
<?php
// By default, any link click or form submission (for those forms with data-pjax attribute) within the body content will trigger an AJAX request.
$form = ActiveForm::begin(['action' => 'test', 'options' => ['data-pjax' => true]]); ?>
<?= $form->field($model, 'line')->textarea()->label('') ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'id' => 'testpjax']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<?php Pjax::end() ?>
I’m really surprised I wasn’t able to figure this out. This isn’t the first time I’ve used Pjax in my project and I could have swore I tried what you suggested… either way. It’s working now and I really appreciate it!