Skip to content

Fix error messages mismatch when creating items#26229

Merged
AlexGaillard merged 10 commits intodirectus:mainfrom
johnson-jnr:cms-1508-fix-validation-error-msgs
Nov 21, 2025
Merged

Fix error messages mismatch when creating items#26229
AlexGaillard merged 10 commits intodirectus:mainfrom
johnson-jnr:cms-1508-fix-validation-error-msgs

Conversation

@johnson-jnr
Copy link
Contributor

@johnson-jnr johnson-jnr commented Nov 19, 2025

Scope

What's changed:

  • In validation-errors component, prop values were passed directly to useValidationErrorDetails using toRef.
  • passing toRef(props.validationErrors) doesn’t keep the prop value properly synchronised.
  • updated the component to pass prop values using toRef's getter syntax to fix discrepancies.

Potential Risks / Drawbacks

  • None that I'm aware of.

Tested Scenarios

  • All 4 scenarios reported in Error messages do not update properly when creating Items #26227 were tested. Reposted below:
  • Attempt to submit an empty form. Required field validation messages will display as expected.
  • Enter a value for Name and submit again. Required field validation messages will still display for both Name and Color, even though Name now has a value.
  • Fill in the required fields and enter invalid values for Must Be Yes and Must Be No. Here, required field validation message go away and the custom validation messages are displayed.
  • Clear out the Name field and hit submit again. The required field validation message for Name will not be displayed, only the already existing custom validation messages.

Review Notes

  • note this toRef(props, 'validationErrors') also works.
  • toRef's doc recommends using the getter syntax for Vue version 3.3+ so I went with that.

Questions

  • This wasn't raised in the issue but needs clarification:
Screenshot 2025-11-20 at 01 43 18

In a case where you have both required and non-required fields in a form, and you submit the form with any of the required fields empty and non-required fields filled with invalid values. The validation errors appear only for the required values. Errors for non-required fields appear only when the required fields are also filled and submitted.

From my investigation, this is because required fields are validated immediately on the client side, but for non-required fields, the request goes to the server first, and if any, the validation errors are returned. This works fine, except that the user would not see all errors at once in a case like this.

Note, this PR does not address this issue. If this is how it is expected to work, then this PR addresses all the bugs raised in the issue.

Checklist

  • Added or updated tests
  • Documentation PR created here or not required
  • OpenAPI package PR created here or not required

Fixes #26227

@johnson-jnr johnson-jnr changed the base branch from main to issue/24092 November 19, 2025 23:54
@johnson-jnr johnson-jnr changed the base branch from issue/24092 to main November 19, 2025 23:54
@johnson-jnr johnson-jnr force-pushed the cms-1508-fix-validation-error-msgs branch from 3758fb8 to 4dca996 Compare November 20, 2025 00:21
@johnson-jnr
Copy link
Contributor Author

johnson-jnr commented Nov 20, 2025

hi @AlexGaillard

The issue is in the validation-errors component, the validationErrors prop holds the correct value, but it is not properly passed to useValidationErrorDetails, so we have discrepancies with validationErrorsWithDetails as shown.

Screenshot 2025-11-19 at 23 35 22

I added a question that needs clarification.
Thanks.

@johnson-jnr johnson-jnr marked this pull request as ready for review November 20, 2025 00:47
@formfcw formfcw self-requested a review November 20, 2025 06:37
Copy link
Contributor

@formfcw formfcw left a comment

Choose a reason for hiding this comment

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

Thank you so much @johnson-jnr ❤️ for your first contribution 🚀
@gaetansenn Thank you for adding tests 🙏

LGTM 🎉

Copy link
Member

@AlexGaillard AlexGaillard left a comment

Choose a reason for hiding this comment

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

🆒🫘

@AlexGaillard AlexGaillard merged commit 073444e into directus:main Nov 21, 2025
65 checks passed
@github-actions github-actions bot added this to the Next Release milestone Nov 21, 2025
@johnson-jnr
Copy link
Contributor Author

@formfcw I'm glad to have made my first contribution, and thanks to @gaetansenn for the help.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error messages do not update properly when creating Items

4 participants