Custom Error Translations
Embedding custom error translations in an application.
Different error messages may be used based on what the current language is. Implement this by setting the i18n translations in the application. Below is an example of how to add translations to custom error messages
Start by creating a new form.
Add a Text Field to the form.
Open Settings > Validation > Custom Validation add the following code:
valid = input === 'example' ? true : 'mycustomerror';
In the application, create the form above and add translations for the error message. The code should look something like the following:
Formio.createForm(document.getElementById('formio'), {
components: [
{
"label": "Text Field",
"applyMaskOn": "change",
"tableView": true,
"validate": {
"custom": "valid = input === 'example' ? true : 'mycustomerror';"
},
"validateWhenHidden": false,
"key": "textField",
"type": "textfield",
"input": true
}
]
}, {
language: 'es',
i18n: {
en: {
"mycustomerror": 'Your name must be example'
},
es: {
"mycustomerror": 'Tu nombre debe ser ejemplo.'
}
}
})At this point, error message language will be set based on what the current language is.
Last updated
Was this helpful?
