-
-
Notifications
You must be signed in to change notification settings - Fork 166
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(app): create better custom error message from the provided input #494
base: main
Are you sure you want to change the base?
Conversation
Please explain this PR. With the changes we recently added in #397, you can access the issue and therefore the current value. You should have everything you need to create rich error messages. |
Hi @fabian-hiller,
i am trying to acheive the same with the custom method, but the current blocked that i am facing is that i am unable to include the provided input along with the error message , example : -
i have done some changes in the "custom" function and made it to accept a third optional parameter which will modify the error message with the provided input, it won't effect anywhere else. and i have also added a test case .
please do let me know if there is something that i am missing, thanks. |
With the latest version you should be able to write the following. Try it out in our playground. I am currently rewriting Valibot and improving the types. I expect that import * as v from 'valibot';
const Schema = v.object(
{
initial: v.string(),
options: v.array(v.string())
},
[
v.custom(
(input) => input.options.includes(input.initial),
// @ts-ignore
(issue) => `Scope: initial_value "${issue.input.initial}" must exist in options`
)
]
); |
@fabian-hiller , |
related discussion #361