Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iamrealfarhanbd/eb34fda59bd27d0cd254364f2634ca7c to your computer and use it in GitHub Desktop.
Save iamrealfarhanbd/eb34fda59bd27d0cd254364f2634ca7c to your computer and use it in GitHub Desktop.
jQuery code to conditionally display a download button (.nt_download_me) in FluentForm when a specific success class (.fluentform_18_success) is present. Ensures the button is shown only after the submit button is clicked and the success class is rendered
jQuery(document).ready(function ($) {
// Function to check if the success message is present
function checkSuccessMessage() {
jQuery('.kt-modal-content').each(function() {
if ($(this).find('.ff-message-success').length > 0) {
// Success message is present
$(this).find('.nt_download_me').show();
console.log('.nt_download button shown');
} else {
// Success message is not present
$(this).find('.nt_download_me').hide();
console.log('.nt_download button hidden');
}
});
}
// Check initially when the document is ready
checkSuccessMessage();
// Check again when the close icon is clicked
$('.kt-modal-close').on('click', function () {
checkSuccessMessage();
});
// Check again when the submit button is clicked
$('.fluentform_wrapper_18 .ff-btn-submit').on('click', function () {
// Introduce a delay before checking to allow for rendering
setTimeout(function () {
checkSuccessMessage();
}, 1000); // You can adjust the delay as needed
});
});
@iamrealfarhanbd
Copy link
Author

iamrealfarhanbd commented Jan 5, 2024

jQuery(function ($) {
    function checkSuccess() {
        $('.kt-modal-content').each(function() {
            var $downloadBtn = $(this).find('.nt_download_me');
            $downloadBtn.toggle($(this).find('.ff-message-success').length > 0);
            console.log($downloadBtn.is(':visible') ? '.nt_download button shown' : '.nt_download button hidden');
        });
    }
    checkSuccess();
    $('.kt-modal-close, .fluentform_wrapper_18 .ff-btn-submit').on('click', function () {
        setTimeout(checkSuccess, 1000);
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment