checkbox can't be unselected

This commit is contained in:
counterweight 2025-02-25 00:52:25 +01:00
parent d308d2f26d
commit fad4e7a174
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
3 changed files with 13 additions and 18 deletions

View file

@ -1,5 +1,5 @@
* {
font-family: 'Courier New', Courier, monospace;
font-family: Arial, Helvetica, sans-serif;
box-sizing: border-box;
}

View file

@ -29,6 +29,8 @@ const btcMethodCheckboxesWarning = document.getElementById(
const btcMethodCheckboxes = [onchainCheckbox, lightningCheckbox];
const publishOfferButton = document.getElementById('button-submit-offer');
function toggleCreateOfferControls() {
createOfferControls.style.display =
createOfferControls.style.display === 'block' ? 'none' : 'block';
@ -92,19 +94,10 @@ function updateBtcInput() {
btcAmountInput.value = formattedSatsAmount;
}
function validateBitcoinMethodCheckboxes() {
let noneChecked = true;
for (const aCheckbox of btcMethodCheckboxes) {
if (aCheckbox.checked) {
noneChecked = false;
}
}
if (noneChecked) {
btcMethodCheckboxesWarning.style.display = 'block';
} else {
btcMethodCheckboxesWarning.style.display = 'none';
function validateBitcoinMethodCheckboxes(clickedCheckbox) {
let checkedCount = btcMethodCheckboxes.filter((cb) => cb.checked).length;
if (checkedCount === 0) {
clickedCheckbox.checked = true;
}
}
@ -141,7 +134,9 @@ eurAmountInput.addEventListener('input', () => {
});
for (const btcMethodCheckbox of btcMethodCheckboxes) {
btcMethodCheckbox.addEventListener('input', () => {
validateBitcoinMethodCheckboxes();
btcMethodCheckbox.addEventListener('click', () => {
validateBitcoinMethodCheckboxes(btcMethodCheckbox);
});
}
updateBtcInput();