-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(framework,novui): controls validation #6428
Conversation
const nestedPath = err.instancePath.split('/').join('.'); | ||
const requiredFieldName = err.params?.missingProperty as string; | ||
|
||
return { | ||
path: err.instancePath, | ||
message: err.message as string, | ||
property: `${nestedPath}${requiredFieldName ? `.${requiredFieldName}` : ''}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For missing required fields, we have to manually had the field name. It is not part of the instancePath. Otherwise we won't show those "required" missing errors on the input
@@ -6,6 +6,7 @@ export type ValidateFunction<T = unknown> = AjvValidateFunction<T> | ((data: T) | |||
|
|||
export type ValidationError = { | |||
path: string; | |||
property: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mapping of the validation error to the schema object uses the property attribute with . and not /
I was wondering why we need the path @rifont ? should we maybe have only one of those (path/property) and where needed change one if those strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right, we should use just one of these. My preference would be to modify the existing path
property to use the .
-separated syntax as I feel the name is better suited to describing a full path, where property
is more singular.
Let's modify the validators to return .
-separated syntax on the path
property and remove the property
entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// adding a default error for the case of errors in an array not updating correctly | ||
return { __errors: ['enableShowExtraErrors'], ...toErrorSchema(errors || []) }; | ||
}; | ||
|
||
// Always return an empty array to prevent the default error messages from showing | ||
function transformErrors(_: RJSFValidationError[]) { | ||
return []; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 praise: Helpful comments, thank you!
commit: |
What changed? Why was the change needed?
Opened instead of this closed PR
Currently, validation is only with the default JSON schema validation
In this PR we ensure that the errors object provided by the validate action maps the errors back to the correct locations in the form (both errors defined in Zod and from Json Schema)
Screenshots
Expand for optional sections
Related enterprise PR
Special notes for your reviewer