Hi Max,
I had to make a small adjustment to the script because I’ve made a lot of changes recently, and the widget is now “Reparatie V3.”
It seems to be working partially, but the field “Telefoonnummer” is not working yet.
See below for my adjustments.
const TARGET_FIELDS = [
{ label: ‘Voornaam’, autocomplete: ‘given-name’, type: ‘text’ },
{ label: ‘Achternaam’, autocomplete: ‘family-name’, type: ‘text’ },
{ label: ‘e-mailadres’, autocomplete: ‘email’, type: ‘email’ },
{ label: ‘Telefoonnummer’, autocomplete: ‘tel’, type: ‘tel’ },
{ label: ‘Straatnaam’, autocomplete: ‘street-address’, type: ‘text’ },
{ label: ‘Huisnummer’, autocomplete: ‘address-line2’, type: ‘text’ },
{ label: ‘Postcode’, autocomplete: ‘postal-code’, type: ‘text’ },
{ label: ‘Plaatsnaam’, autocomplete: ‘address-level2’, type: ‘text’ }
];
function listener(selector, callback) {
const firstTarget = document.querySelector(selector);
if (firstTarget) {
return callback(firstTarget);
}
const observer = new MutationObserver((_, observer) => {
const targetNode = document.querySelector(selector);
if (targetNode) {
observer.disconnect();
setTimeout(() => {
callback(targetNode);
}, 300);
}
});
observer.observe(document.body, { childList: true, subtree: true });
}
function handleUpdateFields(container) {
TARGET_FIELDS.forEach(({ label, type, autocomplete }) => {
const input = container.querySelector(input[aria-label*="${label}"]
);
if (input) {
input.setAttribute(‘autocomplete’, autocomplete);
input.setAttribute(‘type’, type);
}
});
}
listener(‘[class*=“FieldsGrid__Grid-sc”]’, (container) => {
handleUpdateFields(container);
const mutationObserver = new MutationObserver(() => {
handleUpdateFields(container);
});
mutationObserver.observe(container, { childList: true });
});