button active inactive, validate inputs
This commit is contained in:
parent
685fbbbde2
commit
cee31c1623
2 changed files with 67 additions and 34 deletions
|
|
@ -121,16 +121,6 @@ Behaviours:
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
let nymInput;
|
|
||||||
let nymInputValidationWarning;
|
|
||||||
let phoneInput;
|
|
||||||
let whatsappInput;
|
|
||||||
let telegramInput;
|
|
||||||
let emailInput;
|
|
||||||
let nostrInput;
|
|
||||||
let signalInput;
|
|
||||||
let submitProfileButton;
|
|
||||||
|
|
||||||
function debounce(func, wait) {
|
function debounce(func, wait) {
|
||||||
let timeout;
|
let timeout;
|
||||||
return function (...args) {
|
return function (...args) {
|
||||||
|
|
@ -139,7 +129,7 @@ function debounce(func, wait) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateNymInput() {
|
validateNymInput = debounce(() => {
|
||||||
const nymValue = nymInput.value.trim();
|
const nymValue = nymInput.value.trim();
|
||||||
const isValid = nymValue.length >= 3 && nymValue.length <= 128;
|
const isValid = nymValue.length >= 3 && nymValue.length <= 128;
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
|
|
@ -147,28 +137,65 @@ function validateNymInput() {
|
||||||
} else {
|
} else {
|
||||||
nymInputValidationWarning.style.display = 'block';
|
nymInputValidationWarning.style.display = 'block';
|
||||||
}
|
}
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
checkIfSubmittable = debounce((allInputs) => {
|
||||||
|
const nymIsFilled = allInputs.nymInput.value !== '';
|
||||||
|
let atLeastOneContactIsFilled = false;
|
||||||
|
|
||||||
|
for (const contactInput of allInputs.contactInputs) {
|
||||||
|
if (contactInput.value !== '') {
|
||||||
|
atLeastOneContactIsFilled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const buttonShouldBeDisabled = !(nymIsFilled && atLeastOneContactIsFilled);
|
||||||
|
submitProfileButton.disabled = buttonShouldBeDisabled;
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
function onLoadErrands(allInputs) {
|
||||||
|
allInputs.nymInput.addEventListener('input', validateNymInput);
|
||||||
|
|
||||||
|
for (const someInput of allInputs.allInputs) {
|
||||||
|
someInput.addEventListener('input', () => {
|
||||||
|
checkIfSubmittable(allInputs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
checkIfSubmittable(allInputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
validateNymInput = debounce(validateNymInput, 500);
|
const nymInput = document.getElementById('nym-input');
|
||||||
|
const nymInputValidationWarning = document.getElementById(
|
||||||
|
'nym-input-validation-warning'
|
||||||
|
);
|
||||||
|
const phoneInput = document.getElementById('phone-input');
|
||||||
|
const whatsappInput = document.getElementById('whatsapp-input');
|
||||||
|
const telegramInput = document.getElementById('telegram-input');
|
||||||
|
const emailInput = document.getElementById('email-input');
|
||||||
|
const nostrInput = document.getElementById('nostr-input');
|
||||||
|
const signalInput = document.getElementById('signal-input');
|
||||||
|
const submitProfileButton = document.getElementById('submit-profile-button');
|
||||||
|
|
||||||
function onLoadErrands() {
|
const allInputs = {
|
||||||
nymInput = document.getElementById('nym-input');
|
nymInput: nymInput,
|
||||||
nymInputValidationWarning = document.getElementById(
|
contactInputs: [
|
||||||
'nym-input-validation-warning'
|
phoneInput,
|
||||||
);
|
whatsappInput,
|
||||||
phoneInput = document.getElementById('phone-input');
|
telegramInput,
|
||||||
whatsappInput = document.getElementById('whatsapp-input');
|
emailInput,
|
||||||
telegramInput = document.getElementById('telegram-input');
|
nostrInput,
|
||||||
emailInput = document.getElementById('email-input');
|
signalInput,
|
||||||
nostrInput = document.getElementById('nostr-input');
|
],
|
||||||
signalInput = document.getElementById('signal-input');
|
allInputs: [
|
||||||
submitProfileButton = document.getElementById('submit-profile-button');
|
nymInput,
|
||||||
|
phoneInput,
|
||||||
nymInput.addEventListener('input', function (event) {
|
whatsappInput,
|
||||||
validateNymInput();
|
telegramInput,
|
||||||
});
|
emailInput,
|
||||||
}
|
nostrInput,
|
||||||
|
signalInput,
|
||||||
window.onload = () => {
|
],
|
||||||
onLoadErrands();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onLoadErrands(allInputs);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<link rel="stylesheet" href="/css/seca.css" />
|
<link rel="stylesheet" href="/css/seca.css" />
|
||||||
<script src="/javascript/createProfile.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
@ -28,7 +27,13 @@
|
||||||
id="nym-input"
|
id="nym-input"
|
||||||
placeholder="ShadowySuperCoder"
|
placeholder="ShadowySuperCoder"
|
||||||
/></label>
|
/></label>
|
||||||
<p id="nym-input-validation-warning" class="text-warning" style="display: none">Debe tener al menos 3 caracteres.</p>
|
<p
|
||||||
|
id="nym-input-validation-warning"
|
||||||
|
class="text-warning"
|
||||||
|
style="display: none"
|
||||||
|
>
|
||||||
|
Debe tener al menos 3 caracteres.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="over-background">
|
<div class="over-background">
|
||||||
|
|
@ -106,4 +111,5 @@
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
<script src="/javascript/createProfile.js"></script>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue