Skip to content

Expose title property for validated fields #4700

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

lazaromenezes
Copy link

@lazaromenezes lazaromenezes commented Jul 24, 2025

Reasons for making this change

This exposes the title property on RJSFValidationError to allow further custom message formating.

Fixes #4504

In #4504 discussion is mentioned a rjsf-v6 branch that I couldn't find so I'm targeting main instead. If there's another branch I could retarget this PR please let me know.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@@ -97,6 +102,7 @@ export function transformRJSFValidationErrors<
params, // specific to ajv
stack,
schemaPath,
title: uiTitle,
Copy link
Member

@heath-freenome heath-freenome Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix... can you add a unit test in utils to verify this fix? And update the CHANGELOG.md as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I'll try getting something done in the next few days.

@lazaromenezes
Copy link
Author

Fixed some failing tests after my change and updated the changelog. Still thinking in the best way to make a specific test for the change.

@TheOneTheOnlyJJ
Copy link

As the author of #4504, I'm very thankful to see this being taken care of.

I have a single proposal/update here, which is also mentioned in #4504.

Would it be feasible to expose the entire uiOptions object of the incorrect field in its RJSFValidationError?
This way, custom error messages could also be based on information from other uiOptions, such as the description, help, label, emptyvalue, placeholder, etc. This would enable more complex use cases by allowing the creation of custom error messages based on any and every UI option the field has, not strictly limited to the title.
This is especially important when working with runtime dynamic JSON schemas (like my project does).
The title, if present, would be included in the uiOptions object, fixing #4504 as well, but in an even more elegant way, opening up even more possibilities.

With the ui:title being retrieved from uiOptions in this PR, could the parameters and typings of RJSFValidationError be updated to pass the entire uiOptions object instead of just the title?

@nickgros
Copy link
Contributor

nickgros commented Aug 1, 2025

@TheOneTheOnlyJJ would it make sense to merge this, and later you (or @lazaromenezes, or another contributor) could enhance the object with the full uiOptions? Or should we wait for @lazaromenezes to weigh in on your request?

@lazaromenezes
Copy link
Author

@nickgros if maintainers are okay with merging as it is I'm also okay and address uiOptions in a later pull request and put more work on the tests when exposing the full object.

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

Successfully merging this pull request may close these issues.

Expose title/ui:title in RJSFValidationError
4 participants