forms: make value property update a function and update textareas too

This commit is contained in:
Alice Gaudon 2020-09-15 16:30:25 +02:00
parent ab8e756034
commit a92b657e4a

View File

@ -1,13 +1,20 @@
// For labels to update their state (css selectors based on the value attribute) // For labels to update their state (css selectors based on the value attribute)
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('input').forEach(el => { window.updateInputs = () => {
if (el.type !== 'checkbox') { document.querySelectorAll('input, textarea').forEach(el => {
el.setAttribute('value', el.value); if (!el.inputSetup) {
el.addEventListener('change', () => { el.inputSetup = true;
el.setAttribute('value', el.value); if (el.type !== 'checkbox') {
}); el.setAttribute('value', el.value);
} el.addEventListener('change', () => {
}); el.setAttribute('value', el.value);
});
}
}
});
};
updateInputs();
}); });
window.applyFormMessages = function (formElement, messages) { window.applyFormMessages = function (formElement, messages) {