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 = () => {
document.querySelectorAll('input, textarea').forEach(el => {
if (!el.inputSetup) {
el.inputSetup = true;
if (el.type !== 'checkbox') { if (el.type !== 'checkbox') {
el.setAttribute('value', el.value); el.setAttribute('value', el.value);
el.addEventListener('change', () => { el.addEventListener('change', () => {
el.setAttribute('value', el.value); el.setAttribute('value', el.value);
}); });
} }
}
}); });
};
updateInputs();
}); });
window.applyFormMessages = function (formElement, messages) { window.applyFormMessages = function (formElement, messages) {