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

Make server-side validation supportable in the standard save function #8722

Closed
ns-vpanfilov opened this issue Mar 10, 2023 · 2 comments
Closed

Comments

@ns-vpanfilov
Copy link

Is your feature request related to a problem? Please describe.
Currently, server-side validation is only supportable using a custom save function (https://marmelab.com/react-admin/Validation.html#schema-validation).

While that approach works, it has the following limitations:

  • Some configurations that (e.g. transform property for Create) are ignored
  • Building server-side component is more complex that for Create (due to the fact we need to be inside record context), and it is not documented

Describe the solution you'd like
Allow for a configurable parameter that can be passed to Create and Update components that will translate an error and return it to the form as validation results:

const ServerSideValidation = async (e:Error): Promise< undefined | Record<string, {message: string, messageArgs?: any} >> = {

return undefined // no server-side validation errors to be reported

// OR

return {
   user_name: {
      message: 'messages.validation.invalid_chars',
      messageArgs: {'only numbers are allowed}
   }
} // error message to be displayed for 'user_name' field

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@djhi
Copy link
Collaborator

djhi commented Mar 10, 2023

Can you check whether #7938 solves your issue? It's planned for 4.9.0

@ns-vpanfilov
Copy link
Author

it does. thanks

@djhi djhi closed this as completed Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants