SELECTED ANSWER
replied on January 2, 2023
Again, thanks, Rui. I figured out what I had done wrong just after I posted above. I removed the extra document ready in the middle.
$(document).ready(function(){
// create container for cloned nav tabs
let container = $('<div style="display:none !important;"></div>');
// pagination tabs
$('.cf-pagination-tabs li').each(function(){
// clone tab to hidden container
var c = $(this).clone(true, true);
container.append(c);
// remove/replace event handlers
$(this).off().on('click',function(){
// get results of page validation
if (pageValid()) {
$(c).click(); // trigger click on hidden tab
if ($(this).is('li')) $(this).addClass('active'); // make tab active
}
});
});
$('.cf-pagination-tabs').parent().append(container);
// navigation buttons
$('.cf-pagination-btn').each(function(){
// create container for nav buttons
var box = $('<div style="display:none !important;"></div>');
$(this).find('input').each(function(){
// clone button to hidden container
var c = $(this).clone(true,true);
box.append(c);
// remove/replace event handlers
$(this).off().on('click',function(e){
if (pageValid()) $(c).click(); // trigger click on hidden btn
});
});
$(this).append(box);
});
// page validation function
function pageValid(flagErrors = true){
var valid = true; // default output
// validate fields on active page
$('.cf-page.active :input:not([readonly]):visible').each(function(){
// show validation errors
$(this).parsley().validate();
// change output for invalid field if none detected
if (valid && !$(this).parsley().isValid()) {
$(this).focus(); // focus on first error
valid = false; // flag error
}
});
return valid;
}
});