Thanks you so much @van for sharing this. I was struggling with this for a while to use a WP Plugin with Barba page transition.
I would also like to share my implementation.
Before you try this, make a note of the #IDs that you want to remove and their URL or code, as this will be different for different applications/plugins.
function reInitFormidableForms() {
var domain = window.location.origin; // Dynamically gets the domain
// Remove existing Formidable Forms CSS and JavaScript
// jQuery('#formidable-css').remove(); // Uncomment this line if you need to remove CSS. I did not need to remove it.
// Add any of trhe scripts you need to remove
jQuery('#formidable-js-extra').remove();
jQuery('#formidable-js').remove();
jQuery('#formidable-js-after').remove();
jQuery('#formidable_chat-js').remove();
// Delayed re-adding of the scripts and styles
setTimeout(function () {
// Reinitialize CSS
// jQuery('head').append('<link rel="stylesheet" id="formidable-css" href="' + domain + '/wp-content/plugins/formidable/css/formidableforms.css" type="text/css" media="all" />');
// Reinitialize inline JavaScript
// Keep them in the original order
jQuery('body').append('<script id="formidable-js-extra">' +
'var frm_js = {"ajax_url":"' + domain + '\/wp-admin\/admin-ajax.php","images_url":"' + domain + '/wp-content\/plugins\/formidable\/images","loading":"Loading\u2026","remove":"Remove","offset":"4","nonce":"937e963b0f","id":"ID","no_results":"No results match","file_spam":"That file looks like Spam.","calc_error":"There is an error in the calculation in the field with key","empty_fields":"Please complete the preceding required fields before uploading a file.","focus_first_error":"1","include_alert_role":"1"};' +
'var frm_password_checks = {"eight-char":{"label":"Eight characters minimum","regex":"\/^.{8,}$\/","message":"Passwords require at least 8 characters"},"lowercase":{"label":"One lowercase letter","regex":"#[a-z]+#","message":"Passwords must include at least one lowercase letter"},"uppercase":{"label":"One uppercase letter","regex":"#[A-Z]+#","message":"Passwords must include at least one uppercase letter"},"number":{"label":"One number","regex":"#[0-9]+#","message":"Passwords must include at least one number"},"special-char":{"label":"One special character","regex":"\/(?=.*[^a-zA-Z0-9])\/","message":"password is invalid"}};' +
'</script>');
jQuery('body').append('<script src="' + domain + '/wp-content/plugins/formidable-pro/js/frm.min.js" id="formidable-js"></script>');
jQuery('body').append('<script id="formidable-js-after">window.frm_js.repeaterRowDeleteConfirmation = "Are you sure you want to delete this row?";</script>');
jQuery('body').append('<script src="' + domain + '/wp-content/plugins/formidable-chat/js/chat.min.js" id="formidable_chat-js"></script>');
}, 300); // Delay in milliseconds, adjust as needed
}
Then Add the function to the Barba hook as necessary:
barba.hooks.after(() => {
reInitFormidableForms();
});