You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Forms should be user friendly and so should be the errors. Therefore in cases where the form creator wants to have more readable errors for fields they should be allowed to do so.
For example, if a form is asking for a name and is requiring a pattern ^([^0-9]*)$, the current error shown in must match pattern "^([^0-9]*)$". The creator of form might want to show a custom error like Name should not contain numbers.
Adding support for this would enable more user friendly forms. This is handy when the schema comes from the backend and the UI just renders it.
Some implementation using ajv-errors or transformErrors.
Describe alternatives you've considered
Support for custom error messages is present but it has to be driven through code. For the use cases where the schema is coming from the backend there is no way to know the error message before hand.
The text was updated successfully, but these errors were encountered:
@nickgros Thanks, this worked. This plugin architecture is great! Attaching the code here for future references.
importFormfrom"@rjsf/core";import{RJSFSchema}from"@rjsf/utils";import{customizeValidator}from"@rjsf/validator-ajv8";importajvErrorsfrom"ajv-errors";constvalidator=customizeValidator();ajvErrors(validator.ajv);constschema: RJSFSchema={type: "object",properties: {name: {type: "string",title: "Name",pattern: "^([^0-9]*)$",minLength: 3,errorMessage: {pattern: "Name must not contain numbers",minLength: "Name must be at least 3 characters",},},},};constApp=()=>{return<Formschema={schema}validator={validator}/>;};exportdefaultApp;
Prerequisites
What theme are you using?
validator-ajv8
Is your feature request related to a problem? Please describe.
Forms should be user friendly and so should be the errors. Therefore in cases where the form creator wants to have more readable errors for fields they should be allowed to do so.
For example, if a form is asking for a name and is requiring a pattern
^([^0-9]*)$
, the current error shown inmust match pattern "^([^0-9]*)$"
. The creator of form might want to show a custom error likeName should not contain numbers
.Adding support for this would enable more user friendly forms. This is handy when the schema comes from the backend and the UI just renders it.
I think this was being discussed before here.
Describe the solution you'd like
Some implementation using
ajv-errors
ortransformErrors
.Describe alternatives you've considered
Support for custom error messages is present but it has to be driven through code. For the use cases where the schema is coming from the backend there is no way to know the error message before hand.
The text was updated successfully, but these errors were encountered: