I'm trying to create error messages for form validation in multiple languages. Unfortunately, the transfer of the "target" parameter to my function does not work. Maybe target is interpreted as a string?!
function formMessages(field, target) {
var messages = {
'de' : {
'valueMissing': 'Bitte füllen Sie dieses Feld aus.',
'typeMismatch': {
'email': 'Bitte geben Sie eine E-Mail ein.',
'url': 'Bitte geben Sie eine URL ein.'
}
}
};
// Don't work!
// return messages.de.target;
// This works! But it is not dynamic!
// return messages.de.typeMismatch.email;
}
if (validity.typeMismatch) {
// Email
if (field.type === 'email') return formMessages(field, 'typeMismatch.email');
}