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

Add a simple customPartial implementation #223

Closed
wants to merge 2 commits into from

Conversation

Demivan
Copy link
Contributor

@Demivan Demivan commented Oct 24, 2023

Related #76

This is an extremely simplified implementation of the proposed “partial pipe” solution.

@netlify
Copy link

netlify bot commented Oct 24, 2023

Deploy Preview for valibot canceled.

Name Link
🔨 Latest commit 106d176
🔍 Latest deploy log https://app.netlify.com/sites/valibot/deploys/6537784950522f000896cf13

@fabian-hiller fabian-hiller self-assigned this Oct 24, 2023
@fabian-hiller fabian-hiller added the enhancement New feature or request label Oct 24, 2023
@fabian-hiller
Copy link
Owner

Thank you for the draft!

@fabian-hiller
Copy link
Owner

Do you have any alternative name ideas for customPartial. Will it only work or make sense in the pipe of object?

@fabian-hiller fabian-hiller added the priority This has priority label Nov 10, 2023
@fabian-hiller
Copy link
Owner

Beside PR #211, I would like to focus on a solution to this problem in the next week. It will also be important to be able to specify the path where the error message should be applied.

@Demivan
Copy link
Contributor Author

Demivan commented Nov 10, 2023

Do you have any alternative name ideas for customPartial. Will it only work or make sense in the pipe of object?

Maybe something like whenValidated or whenFieldsValid.
It only makes sense with object pipe. So would be nice to have type system prevent usage with other validations.

@fabian-hiller
Copy link
Owner

I have added a partialCheck action and think that we can close this PR. Here is a code example:

import * as v from 'valibot';

const RegisterSchema = v.pipe(
  v.object({
    email: v.pipe(
      v.string(),
      v.nonEmpty('Please enter your email.'),
      v.email('The email address is badly formatted.'),
    ),
    password1: v.pipe(
      v.string(),
      v.nonEmpty('Please enter your password.'),
      v.minLength(8, 'Your password must have 8 characters or more.'),
    ),
    password2: v.string(),
  }),
  v.forward(
    v.partialCheck(
      [['password1'], ['password2']],
      (input) => input.password1 === input.password2,
      'The two passwords do not match.',
    ),
    ['password2'],
  ),
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority This has priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants