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 errorMessage by field name doesn't work. #55

Open
sandrina-p opened this issue Oct 27, 2023 · 1 comment
Open

custom errorMessage by field name doesn't work. #55

sandrina-p opened this issue Oct 27, 2023 · 1 comment

Comments

@sandrina-p
Copy link
Collaborator

sandrina-p commented Oct 27, 2023

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

{
  "properties": {
    "year": {
      "title": "Year",
      "type": "number",
      "presentation": {
        "inputType": "number"
      },
      "x-jsf-errorMessage": {
        "required": "Cannot be empty."
      },
      "minimum": 1900,
      "maximum": 2023
    }
  },
  "required": ["year"]
}

JSF Config:

const { fields } = createHeadlessForm(schemaAbove, {
  customProperties: {
    year: {
      errorMessage: {
        required: "The year is mandatory."
      }
    }
  }
})
@sandrina-p
Copy link
Collaborator Author

sandrina-p commented Oct 30, 2023

This issue might be out of scope for json-schema-form. We are discussing internally the possibility of deprecating customProperties in favor of moving mutations to JSON Schemas outside createHeadlessForm().

So in this case, we'd instead recommend doing this:

import mutate from 'json-schema-form';

const newSchema = mutate(schema, {
  fields: {
    year: {
      "x-jsf-errorMessage": {
        required: "Cannot be empty (custom error)"
      }
    },
  }
});

const form = createHeadlessForm(newSchema)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant