<div class='tpl-job-alert-page'>
</div>
<div class='tpl-job-alert-page'>
</div>
/* No context defined. */
.tpl-job-alert-page {
@apply pt-[calc(var(--content-padding-top))] overflow-hidden;
.job-alert-form-intro {
@apply max-w-[768px];
.atm-heading {
@apply text-secondary-col-1;
}
}
}
(function () {
'use strict';
// Function to pre-fill the form
function preFillJobAlertForm() {
const jobAlertForm = document.getElementById('job-alert-form');
if (!jobAlertForm) {
return;
}
// Get all data attributes from the form container
const formData = {
email: jobAlertForm.getAttribute('data-email'),
firstName: jobAlertForm.getAttribute('data-first-name'),
lastName: jobAlertForm.getAttribute('data-last-name'),
location: jobAlertForm.getAttribute('data-location'),
distance: jobAlertForm.getAttribute('data-distance'),
contractType: jobAlertForm.getAttribute('data-contract-type'),
workEnvironment: jobAlertForm.getAttribute('data-work-environment'),
categories: jobAlertForm.getAttribute('data-categories')
};
// Check if we have any data to pre-fill
const hasData = Object.values(formData).some(value => value !== null && value !== '');
if (!hasData) {
return;
}
// Wait for Umbraco Forms to render
let attempts = 0;
const maxAttempts = 50;
const waitForFormFields = setInterval(function () {
attempts++;
const formElement = jobAlertForm.querySelector('form');
if (!formElement) {
if (attempts >= maxAttempts) {
clearInterval(waitForFormFields);
}
return;
}
// Try to find and fill form fields
let fieldsFound = 0;
// Map fields based on class names
var fieldClassMap = {
'email': 'email',
'firstName': 'firstname',
'lastName': 'lastname',
'location': 'location'
};
// Fill text inputs using class names
Object.keys(fieldClassMap).forEach(function (fieldKey) {
if (formData[fieldKey]) {
var className = fieldClassMap[fieldKey];
var fieldContainer = formElement.querySelector('.umbraco-forms-field.' + className);
if (fieldContainer) {
var field = fieldContainer.querySelector('input, textarea');
if (field) {
field.value = formData[fieldKey];
field.classList.add('filled');
fieldsFound++;
}
}
}
});
// Fill distance (range slider or number input)
if (formData.distance) {
const distanceContainer = formElement.querySelector('.umbraco-forms-field.distance');
if (distanceContainer) {
const distanceField = distanceContainer.querySelector('input');
if (distanceField) {
distanceField.value = formData.distance;
// Trigger change event for range slider
const event = new Event('input', { bubbles: true });
distanceField.dispatchEvent(event);
fieldsFound++;
}
}
}
// Fill checkboxes for contractType
if (formData.contractType) {
const contractTypeContainer = formElement.querySelector('.umbraco-forms-field.contracttype');
if (contractTypeContainer) {
const contractTypes = formData.contractType.split(',');
contractTypes.forEach(function (type) {
const trimmedType = type.trim();
const checkboxes = contractTypeContainer.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(function(checkbox) {
const label = checkbox.parentElement.textContent.trim();
if (label.toLowerCase().indexOf(trimmedType.toLowerCase()) !== -1) {
checkbox.checked = true;
fieldsFound++;
}
});
});
}
}
// Fill checkboxes for workEnvironment
if (formData.workEnvironment) {
const environmentContainer = formElement.querySelector('.umbraco-forms-field.environment');
if (environmentContainer) {
const environments = formData.workEnvironment.split(',');
environments.forEach(function (env) {
const trimmedEnv = env.trim();
const checkboxes = environmentContainer.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(function(checkbox) {
const label = checkbox.parentElement.textContent.trim();
if (label.toLowerCase().indexOf(trimmedEnv.toLowerCase()) !== -1) {
checkbox.checked = true;
fieldsFound++;
}
});
});
}
}
// Fill checkboxes for categories
if (formData.categories) {
const categoriesContainer = formElement.querySelector('.umbraco-forms-field.categories');
if (categoriesContainer) {
const categoriesList = formData.categories.split(',');
categoriesList.forEach(function (interest) {
const trimmedInterest = interest.trim();
const checkboxes = categoriesContainer.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(function(checkbox) {
const label = checkbox.parentElement.textContent.trim();
if (label.toLowerCase().indexOf(trimmedInterest.toLowerCase()) !== -1) {
checkbox.checked = true;
fieldsFound++;
}
});
});
}
}
// If we found fields, stop checking
if (fieldsFound > 0) {
clearInterval(waitForFormFields);
}
}, 100);
// Stop trying after 5 seconds
setTimeout(function () {
clearInterval(waitForFormFields);
}, 5000);
}
// Wait for DOM to be fully loaded
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', preFillJobAlertForm);
} else {
// DOM is already loaded
preFillJobAlertForm();
}
})();
No notes defined.