formio / formio.js

JavaScript powered Forms with JSON Form Builder
https://formio.github.io/formio.js
MIT License
1.83k stars 1.04k forks source link

The errorLabel is replaced with translated key when key is used as label in required component #5618

Closed LukacTomas closed 2 weeks ago

LukacTomas commented 1 month ago

Describe the bug When the label for any required component is matching the key from translations file Then the errorLabel is replaced with translated key.

Version/Branch 4.19.x

To Reproduce

  1. Create form with (say) required textinput have have one key from translation file as a label (say: invalidRowsError)
  2. Submit form
  3. See error labels

Expected behavior Error label should be invalidRowsError. Instead it's its translated version: Please correct invalid rows before proceeding.

Screenshots image

Additional context

{
  "display": "form",
  "settings": {
    "pdf": {
      "id": "1ec0f8ee-6685-5d98-a847-26f67b67d6f0",
      "src": "https://files.form.io/pdf/5692b91fd1028f01000407e3/file/1ec0f8ee-6685-5d98-a847-26f67b67d6f0"
    }
  },
  "components": [
    {
      "label": "invalidRowsError",
      "applyMaskOn": "change",
      "tableView": true,
      "validate": {
        "required": true
      },
      "key": "invalidRowsError",
      "type": "textfield",
      "input": true
    },
    {
      "label": "Text Field",
      "applyMaskOn": "change",
      "tableView": true,
      "validate": {
        "required": true
      },
      "key": "textField",
      "type": "textfield",
      "input": true
    },
    {
      "type": "button",
      "label": "Submit",
      "key": "submit",
      "input": true,
      "tableView": false
    }
  ]
}
ZenMasterJacob20011 commented 2 weeks ago

The keys in the translation file are used to translate the keys text into the translated text. It is expected that when you have a label that has the same text as the key text in the translation file, the label and the error message that uses the label will be have the translated label. For example, if you have a label that matches a translation key like invalidRowsError then the label should be...

and the error message for the required error should be...

This behavior is occurring because the label matches the a key in the translations file

To have the behavior you are expecting you will need to override the invalidRowsError key in the translation file. Here is a jsfiddle that shows how to do this.