{% load i18n %} {% load labelbase_tags %} {% load sekizai_tags %} {% load bootstrap %} {% if labelbase %} {% else %} {% endif %} {% addtoblock "js" %} $("#export-label-form").submit(function(e) { // Remove the buttons and hide form fields $('#exportButton').prop('disabled', true); $('#export-label-modal-body').hide(); // Display the success message $('#successMessage').removeClass('d-none'); }); // Enable/disable passphrase input based on the "Encrypt" checkbox const encryptCheckbox = $("#id_encrypt_checkbox"); const passphraseInput = $("#id_passphrase"); const exportButton = $("#exportButton"); const formGroup = encryptCheckbox.closest(".form-group"); const obj_hr = $("
"); const obj_br2 = $("
"); formGroup.before(obj_hr); // Add
before the parent form-group of the encryptCheckbox const passphraseLabel = $('label[for="id_passphrase"].control-label'); passphraseLabel.before(obj_br2); // Create an array of all the checkboxes that should enable the Export button const checkboxesToMonitor = [ $("#id_tx_checkbox"), $("#id_addr_checkbox"), $("#id_pubkey_checkbox"), $("#id_input_checkbox"), $("#id_output_checkbox"), $("#id_xpub_checkbox"), ]; // Add change event handlers for all checkboxes checkboxesToMonitor.forEach(function(checkbox) { checkbox.change(toggleExportButton); }); encryptCheckbox.change(function() { togglePassphraseInput(); toggleExportButton(); }); passphraseInput.on("input", toggleExportButton); // Function to toggle the passphrase input state function togglePassphraseInput() { const isEncryptChecked = encryptCheckbox.prop("checked"); passphraseInput.prop("disabled", !isEncryptChecked); if (!isEncryptChecked) { passphraseInput.val(""); // Empty passphrase input if encryption is not checked } } // Function to toggle the Export button state function toggleExportButton() { const isEncryptChecked = encryptCheckbox.prop("checked"); var passphraseValue = ""; if (passphraseInput.length) { passphraseValue = passphraseInput.val().trim(); } else { console.log('passphraseInput element not found.'); } const anyCheckboxChecked = checkboxesToMonitor.some(function(checkbox) { return checkbox.prop("checked"); }); // Disable the export button if encryption is checked and the passphrase is empty, // or if nothing is checked exportButton.prop("disabled", (isEncryptChecked && passphraseValue === "") || !anyCheckboxChecked); if (isEncryptChecked) { // If encryption is checked, add 'alert-warning' and remove 'alert-light' $('#export_enc_warning').addClass('alert-warning').removeClass('alert-light'); } else { // If encryption is unchecked, add 'alert-light' and remove 'alert-warning' $('#export_enc_warning').addClass('alert-light').removeClass('alert-warning'); } } $(document).ready(function() { // Initialize the button and input states togglePassphraseInput(); toggleExportButton(); }); {% endaddtoblock %}