commit
8a86a7cf09
|
|
@ -1836,6 +1836,13 @@
|
|||
// Next button logic
|
||||
nextButtons.forEach(button => {
|
||||
button.addEventListener("click", function () {
|
||||
if (currentStep === 0) {
|
||||
// Validate employer history fields before proceeding
|
||||
if (!validateEmployerHistory()) {
|
||||
return false; // Stop navigation
|
||||
}
|
||||
}
|
||||
|
||||
if (validateStep(currentStep)) {
|
||||
if (currentStep < steps.length - 1) {
|
||||
currentStep++;
|
||||
|
|
@ -1844,6 +1851,181 @@
|
|||
}
|
||||
});
|
||||
});
|
||||
function validateEmployerHistory() {
|
||||
const employerTable = document.getElementById('previous_employer_table_body');
|
||||
const rows = employerTable.querySelectorAll('tr');
|
||||
let hasErrors = false;
|
||||
|
||||
rows.forEach(row => {
|
||||
// Get the cells for this row
|
||||
const companyNameInput = row.querySelector('input[name="company_name"]');
|
||||
const designationInput = row.querySelector('input[name="designation"]');
|
||||
const dojInput = row.querySelector('input[name="doj"]');
|
||||
|
||||
// Check if ANY field in this row has a value
|
||||
const hasValues = Array.from(row.querySelectorAll('input')).some(input =>
|
||||
input.value && input.value.trim() !== ''
|
||||
);
|
||||
|
||||
if (hasValues) {
|
||||
// If any field has value, check required fields
|
||||
if (!companyNameInput || !companyNameInput.value.trim()) {
|
||||
companyNameInput.classList.add("is-invalid");
|
||||
companyNameInput.required = true;
|
||||
hasErrors = true;
|
||||
} else {
|
||||
companyNameInput.classList.remove("is-invalid");
|
||||
}
|
||||
|
||||
if (!designationInput || !designationInput.value.trim()) {
|
||||
if (designationInput) {
|
||||
designationInput.classList.add("is-invalid");
|
||||
designationInput.required = true;
|
||||
hasErrors = true;
|
||||
}
|
||||
} else {
|
||||
if (designationInput) designationInput.classList.remove("is-invalid");
|
||||
}
|
||||
|
||||
if (!dojInput || !dojInput.value.trim()) {
|
||||
if (dojInput) {
|
||||
dojInput.classList.add("is-invalid");
|
||||
dojInput.required = true;
|
||||
hasErrors = true;
|
||||
}
|
||||
} else {
|
||||
if (dojInput) dojInput.classList.remove("is-invalid");
|
||||
}
|
||||
} else {
|
||||
// No values in this row, remove validation
|
||||
if (companyNameInput) {
|
||||
companyNameInput.classList.remove("is-invalid");
|
||||
companyNameInput.required = false;
|
||||
}
|
||||
if (designationInput) {
|
||||
designationInput.classList.remove("is-invalid");
|
||||
designationInput.required = false;
|
||||
}
|
||||
if (dojInput) {
|
||||
dojInput.classList.remove("is-invalid");
|
||||
dojInput.required = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Also check the "experience" radio buttons
|
||||
const experienceRadios = document.querySelectorAll('input[name="experience"]');
|
||||
const isExperienced = Array.from(experienceRadios).some(radio =>
|
||||
radio.value === 'experienced' && radio.checked
|
||||
);
|
||||
|
||||
if (isExperienced) {
|
||||
// If user selected "Experienced", check if at least one employer is filled
|
||||
const anyEmployerFilled = Array.from(rows).some(row => {
|
||||
return Array.from(row.querySelectorAll('input')).some(input =>
|
||||
input.value && input.value.trim() !== ''
|
||||
);
|
||||
});
|
||||
|
||||
if (!anyEmployerFilled) {
|
||||
alert("Please fill at least one employer detail since you selected 'Experienced'");
|
||||
hasErrors = true;
|
||||
}
|
||||
}
|
||||
|
||||
return !hasErrors;
|
||||
}
|
||||
|
||||
// Add real-time validation as user types
|
||||
const employerInputs = document.querySelectorAll('#previous_employer_table_body input');
|
||||
employerInputs.forEach(input => {
|
||||
input.addEventListener('input', function() {
|
||||
// When user types in any employer field, validate that row
|
||||
const row = this.closest('tr');
|
||||
if (row) {
|
||||
validateRow(row);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Add change event to experience radio buttons
|
||||
const experienceRadios = document.querySelectorAll('input[name="experience"]');
|
||||
experienceRadios.forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
if (this.value === 'experienced' && this.checked) {
|
||||
// Make first employer row required
|
||||
const firstRow = document.querySelector('#previous_employer_table_body tr');
|
||||
if (firstRow) {
|
||||
const companyNameInput = firstRow.querySelector('input[name="company_name"]');
|
||||
const designationInput = firstRow.querySelector('input[name="designation"]');
|
||||
const dojInput = firstRow.querySelector('input[name="doj"]');
|
||||
|
||||
if (companyNameInput) companyNameInput.required = true;
|
||||
if (designationInput) designationInput.required = true;
|
||||
if (dojInput) dojInput.required = true;
|
||||
}
|
||||
} else if (this.value === 'fresher' && this.checked) {
|
||||
// Remove required from all employer fields
|
||||
const allInputs = document.querySelectorAll('#previous_employer_table_body input');
|
||||
allInputs.forEach(input => {
|
||||
input.required = false;
|
||||
input.classList.remove("is-invalid");
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Helper function to validate a single row
|
||||
function validateRow(row) {
|
||||
const companyNameInput = row.querySelector('input[name="company_name"]');
|
||||
const designationInput = row.querySelector('input[name="designation"]');
|
||||
const dojInput = row.querySelector('input[name="doj"]');
|
||||
|
||||
// Check if ANY field in this row has a value
|
||||
const hasValues = Array.from(row.querySelectorAll('input')).some(input =>
|
||||
input.value && input.value.trim() !== ''
|
||||
);
|
||||
|
||||
if (hasValues) {
|
||||
// Set required attributes
|
||||
if (companyNameInput) companyNameInput.required = true;
|
||||
if (designationInput) designationInput.required = true;
|
||||
if (dojInput) dojInput.required = true;
|
||||
|
||||
// Validate
|
||||
if (companyNameInput && !companyNameInput.value.trim()) {
|
||||
companyNameInput.classList.add("is-invalid");
|
||||
} else if (companyNameInput) {
|
||||
companyNameInput.classList.remove("is-invalid");
|
||||
}
|
||||
|
||||
if (designationInput && !designationInput.value.trim()) {
|
||||
designationInput.classList.add("is-invalid");
|
||||
} else if (designationInput) {
|
||||
designationInput.classList.remove("is-invalid");
|
||||
}
|
||||
|
||||
if (dojInput && !dojInput.value.trim()) {
|
||||
dojInput.classList.add("is-invalid");
|
||||
} else if (dojInput) {
|
||||
dojInput.classList.remove("is-invalid");
|
||||
}
|
||||
} else {
|
||||
// No values, remove requirements
|
||||
if (companyNameInput) {
|
||||
companyNameInput.required = false;
|
||||
companyNameInput.classList.remove("is-invalid");
|
||||
}
|
||||
if (designationInput) {
|
||||
designationInput.required = false;
|
||||
designationInput.classList.remove("is-invalid");
|
||||
}
|
||||
if (dojInput) {
|
||||
dojInput.required = false;
|
||||
dojInput.classList.remove("is-invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Previous button logic
|
||||
prevButtons.forEach(button => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue