Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
denatys opened this issue Mar 22, 2024 · 3 comments
Open

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

denatys opened this issue Mar 22, 2024 · 3 comments
Labels
good first issue Good for newcomers new feature New feature or request

Comments

@denatys
Copy link

denatys commented Mar 22, 2024

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

@denatys denatys changed the title Custom Error Messages by inputType doesn't work Custom Error Messages doesn't work in JSF Config Mar 22, 2024
@denatys
Copy link
Author

denatys commented Mar 22, 2024

formErrors: pet_name: "Required field"

@sandrina-p
Copy link
Collaborator

Hi @denatys,

inputTypes only supports keys that match input types like text, number, etc. It does not support generic errorTypes. As the pet_name is a text, you need to pass its type like this:

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

@sandrina-p
Copy link
Collaborator

We understand that this might not solve what you need (apply a given message to every error type of "required"), so this can be considered a missing feature. If you can, contributions are welcome ✌️

@sandrina-p sandrina-p added new feature New feature or request good first issue Good for newcomers labels Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers new feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants