For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

  1. Start by creating a new form.

  2. Add a Text Field to the form.

  3. Open Settings > Validation > Custom Validation add the following code:

valid = input === 'example' ? true : 'mycustomerror';

  1. 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.

To interpolate data from the form, use the {{}} notation. For example, to interpolate the current input being typed in, change 'Your name must be example' to 'Your name can't be {{data.textField}}'

Last updated

Was this helpful?