dodata provera za email i orgnaziation name
This commit is contained in:
@@ -73,13 +73,13 @@ function setUpNavigation() {
|
||||
// check if next button should be enabled on every input, checkbox and radio button bellow class of .question change
|
||||
const inputs = document.querySelectorAll('.question input, .question select, .question textarea');
|
||||
inputs.forEach(input => {
|
||||
input.addEventListener('change', setNextButtonAvailability);
|
||||
input.addEventListener('change',()=> setNextButtonAvailability());
|
||||
input.addEventListener('blur', () => setNextButtonAvailability());
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
function setNextButtonAvailability() {
|
||||
async function setNextButtonAvailability() {
|
||||
console.log('Setting next button availability');
|
||||
// check if current question is answered
|
||||
// and then enable the next button, disable it otherwise
|
||||
@@ -91,8 +91,14 @@ function setNextButtonAvailability() {
|
||||
if (document.currentQuestion === 0) {
|
||||
const name = document.getElementById('name');
|
||||
const email = document.getElementById('email');
|
||||
const errorDiv = document.getElementById('org-email-error');
|
||||
|
||||
if (name && email && name.value.trim() && email.value.trim()) {
|
||||
nextEnabled = true;
|
||||
nextEnabled = await validateFormFields(nextButton, errorDiv);
|
||||
}else{
|
||||
nextButton.disabled = true;
|
||||
if (errorDiv) errorDiv.textContent = '';
|
||||
return
|
||||
}
|
||||
} else {
|
||||
const inputs = currentQuestion.querySelectorAll('input, select, textarea');
|
||||
@@ -181,4 +187,23 @@ function setButtonVisiblity(buttonId, visible) {
|
||||
}
|
||||
}
|
||||
|
||||
async function validateFormFields(nextBtn, errorDiv) {
|
||||
const nameInput = document.getElementById('name');
|
||||
const emailInput = document.getElementById('email');
|
||||
const name = nameInput.value.trim();
|
||||
const email = emailInput.value.trim();
|
||||
|
||||
const resp = await fetch(`/api/validate_form_fields/?name=${name}&email=${email}`);
|
||||
const data = await resp.json();
|
||||
if (data.errors && (data.errors.name || data.errors.email)) {
|
||||
errorDiv.textContent = (data.errors.name || '') + ' ' + (data.errors.email || '');
|
||||
nextBtn.disabled = true;
|
||||
return false;
|
||||
} else {
|
||||
errorDiv.textContent = '';
|
||||
nextBtn.disabled = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user