at least one checkbox

This commit is contained in:
counterweight 2025-02-24 12:04:36 +01:00
parent 940b833418
commit c4155b0b5d
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
2 changed files with 43 additions and 3 deletions

View file

@ -21,6 +21,14 @@ const buttonDecreasePremium = document.getElementById(
const eurAmountInput = document.getElementById('input-eur-amount');
const btcAmountInput = document.getElementById('input-btc-amount');
const onchainCheckbox = document.getElementById('onchain-checkbox');
const lightningCheckbox = document.getElementById('lightning-checkbox');
const btcMethodCheckboxesWarning = document.getElementById(
'at-least-one-checkbox'
);
const btcMethodCheckboxes = [onchainCheckbox, lightningCheckbox];
function toggleCreateOfferControls() {
createOfferControls.style.display =
createOfferControls.style.display === 'block' ? 'none' : 'block';
@ -82,6 +90,22 @@ 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';
}
}
buttonStartCreateOffer.addEventListener('click', () => {
toggleCreateOfferControls();
});
@ -112,3 +136,9 @@ eurAmountInput.addEventListener('blur', () => {
eurAmountInput.addEventListener('input', () => {
eurAmountInput.value = eurAmountInput.value.replace(/[^0-9]/g, '');
});
for (btcMethodCheckbox of btcMethodCheckboxes) {
btcMethodCheckbox.addEventListener('input', () => {
validateBitcoinMethodCheckboxes();
});
}