Thanks. I ended up finding a way but it's a bit complicated, but if it helps someone else my solution if below.
The only other issue I have is that the Save spinner causes a weird flash of the bottom of the form. Is there anyway to turn off the spiiner or just hide it? I tried hiding .cred-loading-indicator, .wpt-cred-spinner, and related classes with CSS, but the flicker still happens. Is there a reliable way to disable or remove the spinner animation entirely, or at least prevent it from forcing a redraw inside the modal?
The way to move the modal outside the View loop and then use AJAX to dynamically load the correct form for the clicked post.
Here’s thmye working setup:
1. Add a trigger button inside the View loop:
[code]
<button type="button" class="btn btn-sm btn-primary btn-trigger-reassign" data-id="[wpv-post-id]" data-toggle="modal" data-target="#reassignModal">
Reassign
</button>
[/code]
2. Placed a single modal outside the View loop:
[code]
<div class="modal fade" id="reassignModal" tabindex="-1" role="dialog"> <div class="modal-dialog modal-dialog-centered" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title">Change Owner</h5> <button type="button" class="close" data-dismiss="modal">×</button> </div> <div class="modal-body" id="reassign-content-placeholder"> <p class="small text-muted">Loading…</p> </div> </div> </div> </div>
[/code]
3. JS to load the form dynamically (added in the html block that has the modal code):
[code]
jQuery(function($){
// delegated click so it still works after filtering
$(document).on('click', '.btn-trigger-reassign', function(){
const postId = $(this).data('id');
$('#reassign-content-placeholder').html('<p class="small text-muted">Loading…</p>');
$.ajax({
url: window.ajaxurl,
type: 'POST',
data: {
action: 'load_reassign_modal_form',
post_id: postId
},
success: function(resp){
$('#reassign-content-placeholder').html(resp);
},
error: function(){
$('#reassign-content-placeholder').html('<p class="text-danger">Error loading form.</p>');
}
});
});
});
[/code]
4. PHP callback in functions.php:
[code]
add_action('wp_ajax_load_reassign_modal_form', 'load_reassign_modal_form_callback');
add_action('wp_ajax_nopriv_load_reassign_modal_form', 'load_reassign_modal_form_callback');
function load_reassign_modal_form_callback() {
if (empty($_POST['post_id'])) wp_die('No post ID');
$post_id = intval($_POST['post_id']);
// temporarily set the global $post so Toolset can "see" it
$GLOBALS['post'] = get_post($post_id);
setup_postdata($GLOBALS['post']);
echo do_shortcode('[cred_form form="change-client-case-owner" post="' . $post_id . '"]');
wp_reset_postdata();
wp_die();
}
[/code]