Ajv-errors custom error message

Hi,

I’m attempting to override the error messaging. Please see my schema and ui schema:

Schema:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "type": "object",
  "properties": {
    "Cat": {
      "type": "string"
    },
    "Dog": {
      "type": "string"
    },
    "Fish": {
      "type": "string"
    }
  },
  "required": ["Cat", "Dog"],
  "errorMessage": {
    "required": {
      "Cat": "Cat is required"
    }
  }
}

UI Schema:

{
  "type": "VerticalLayout",
  "elements": [
    {
      "type": "Group",
      "elements": [
        {
          "type": "Control",
          "scope": "#/properties/Cat",
          "label": "Cat"
        },
        {
          "type": "Control",
          "scope": "#/properties/Dog",
          "label": "Dog"
        },
        {
          "type": "Control",
          "scope": "#/properties/Fish",
          "label": "Fish"
        }
      ]
    }
  ]
}

and in the component I am using createAjv and then using ajvErrors:

  ajv = createAjv({
    allErrors: true,
    verbose: true,
  });

  constructor() {
    ajvErrors(this.ajv);
    // Also tried this:
    // this.ajv = ajvErrors(this.ajv);
  }

html:

<jsonforms
  [data]="data"
  [schema]="schema"
  [uischema]="uischema"
  [renderers]="renderers"
  [i18n]="i18n"
  [ajv]="ajv"
  (dataChange)="onDataChange($event)"
  validationMode="ValidateAndShow"
></jsonforms>

Notice, the override is kind of recognised (because the default error now doesn’t show) but the new message doesn’t show on that field.

Screenshot 2023-09-11 at 17.43.52

Any help appreciated.

I’d like to be able to override errors generically, in this case, replacing all “required” messages with something else with the option to tailor some and ideally, defining these somewhere outside of the schemas and perhaps in the json-forms props?

Hi @charlie ,
did you already have a look at the i18n documentation for errors on the website: i18n - JSON Forms ?

You should be able to translate errors via your translate function provided as part of the i18n object handed into the jsonforms component. Thereby, JsonForms derives an i18n key from the error.
This is a property specific key (e.g. Cat.error.required for your Cat property). To generally provide a translation for all errors of a type, i18n key error.<error> (e.g. error.required) is used.

Could this solve your problem?