I need to pass the pajax id to my modal view’s javascript beforeSubmit event and struggling to get the right syntax.
Currently I was passing the pajax id to a hidden control on the modal and retrieving it in the event, this works and I’ve confirmed it is correct, but I can’t get the $.pjax.reload({container: statement to work with it.
Below is one of my many attempt.
var pjaxContainer = $('#pjaxId').val();
console.log(pjaxContainer);
$.pjax.reload({container:"#"+pjaxContainer, timeout:5000, async:false}); //This is the line I need help with to accept a variable for the container.
Update 1
Below are few attempts that I tried that failed
var pjaxContainerName = $('#pjaxId').val();
var pjaxContainer = $('#' + pjaxContainerName);
$.pjax.reload({
// static pjax ids
// *********************************
// container: '#projectsListGrid', // Normal way that works
// dynamic pjax ids - can't get this approach to work
// *********************************
// container: "#"+pjaxContainer.attr('id'), //no error, but whole page reloads
// container: pjaxContainerName, //uncaught exception: the container selector 'projectsListGrid5d2fa662b163c' did not match anything
// container: "#"+pjaxContainerName, //no error, but whole page reloads
// container: pjaxContainer, // uncaught exception: expected string value for 'container' option; got object
// container: function(){ return '#'+pjaxContainerName; }, // uncaught exception: expected string value for 'container' option; got function
timeout:5000,
async:false
});
The reason that it is dynamically named is to get around the issue with modal calls make multiple requests. My index view for the creation of the pjax container is
<?php
$uniqid = uniqid();
Pjax::begin([
'id'=>'projectsListGrid'.$uniqid,
'enablePushState' => false,
'options' => ['data-pjax' => true],
'timeout' => 5000,
]);
?>