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

Change error massage param to function #136

Closed
wants to merge 1 commit into from

Conversation

vicimpa
Copy link
Contributor

@vicimpa vicimpa commented Sep 1, 2023

For multi language. Example:

const LoginSchema = object({
  email: string([
    minLength(1, () => 'Please enter your email.'),
    email(() => 'The email address is badly formatted.'),
  ]),
  password: string([
    minLength(1, () => 'Please enter your password.'),
    minLength(8, () => 'Your password must have 8 characters or more.'),
  ]),
});

@netlify
Copy link

netlify bot commented Sep 1, 2023

Deploy Preview for valibot ready!

Name Link
🔨 Latest commit 0bcdca1
🔍 Latest deploy log https://app.netlify.com/sites/valibot/deploys/64f22fbc5d6ff1000857d68b
😎 Deploy Preview https://deploy-preview-136--valibot.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@fabian-hiller
Copy link
Owner

Thank you very much! Do you have an opinion on this issue? #36

@fabian-hiller fabian-hiller self-assigned this Sep 1, 2023
@fabian-hiller fabian-hiller added the enhancement New feature or request label Sep 1, 2023
@vicimpa
Copy link
Contributor Author

vicimpa commented Sep 3, 2023

Yes, sure. See.

const LoginSchema = object({
  email: string([
    minLength(1, () => i18n["min_length"]),
    email(() => i18n["email_fail"]),
  ])
});

@ragokan
Copy link

ragokan commented Sep 3, 2023

Just wanted to comment, that looks pretty good for localization.

@fabian-hiller
Copy link
Owner

I haven't made a decision about i18n yet. If you have a clear opinion, feel free to tell more about why this solution is better than the other ones in #36.

@vicimpa
Copy link
Contributor Author

vicimpa commented Sep 9, 2023

My solution is more universal and is not tied to the i18n library

@thundermiracle
Copy link
Contributor

Is there anyone who agrees that passing messages or functions to every validation function is inconvenient as I do?

@fabian-hiller
Copy link
Owner

@thundermiracle are you interested in a global solution to pass individual error messages?

@thundermiracle
Copy link
Contributor

@thundermiracle are you interested in a global solution to pass individual error messages?

Yes, of course. What's the solution?

@fabian-hiller
Copy link
Owner

There are several ideas in issue #36. Which one do you prefer?

@thundermiracle
Copy link
Contributor

There are several ideas in issue #36. Which one do you prefer?

I'm not sure. But

  1. Passing functions or messages to every function is not preferable
  2. Adding global state as gmaxlev suggested is not that good in functional programming

What about record map which support both string and function which others suggested?

Maybe we should discuss it in #36 ?

@fabian-hiller
Copy link
Owner

Yes, please share your ideas and feedback there. I plan to work on an implementation next week.

@fabian-hiller
Copy link
Owner

Thanks again for creating this PR. Since I would do some basic things differently and it was faster for me to implement them directly, I made the changes independently. However, I have added you as a co-author and linked the PR in the changelog.

fabian-hiller added a commit that referenced this pull request Sep 17, 2023
Co-authored-by: PromiSe#### <vicimpa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants