Skip to content

Custom Error Messages doesn't work in JSF Config #69

Description

@denatys

Given the following JSON Schema, I cannot override errorMessage using createHeadlessForm()

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "browsers": {
      "title": "Browsers (solo)",
      "description": "This solo select also includes a disabled option.",
      "type": "string",
      "oneOf": [
        {
          "const": "chr",
          "title": "Chrome"
        },
        {
          "const": "ff",
          "title": "Firefox"
        },
        {
          "const": "ie",
          "title": "Internet Explorer",
          "disabled": true
        }
      ],
      "x-jsf-presentation": {
        "inputType": "select"
      }
    },
    "has_pet": {
      "title": "Has Pet",
      "description": "Do you have a pet?",
      "oneOf": [
        {
          "title": "Yes",
          "const": "yes"
        },
        {
          "title": "No",
          "const": "no"
        }
      ],
      "x-jsf-presentation": {
        "inputType": "radio"
      },
      "type": "string"
    },
    "pet_name": {
      "title": "Pet's name",
      "description": "What's your pet's name?",
      "x-jsf-presentation": {
        "inputType": "text"
      },
      "type": "string",
      "errorMessage": "string"
    }
  },
  "required": ["has_pet"],
  "x-jsf-order": ["has_pet", "pet_name"],
  "allOf": [
    {
      "if": {
        "properties": {
          "has_pet": {
            "const": "yes"
          }
        },
        "required": ["has_pet"]
      },
      "then": {
        "required": ["pet_name"]
      },
      "else": {
        "properties": {
          "pet_name": false
        }
      }
    }
  ]
}

JSF Config:

    const { fields, handleValidation } = createHeadlessForm(Schema, {
      inputTypes: {
        errorMessage: {
          required: 'This cannot be empty.',
        },
      },
    });

This is very important to be able to i18n in the application

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions