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

setLocale not working #11

Open
Reocin opened this issue Dec 20, 2022 · 4 comments
Open

setLocale not working #11

Reocin opened this issue Dec 20, 2022 · 4 comments

Comments

@Reocin
Copy link

Reocin commented Dec 20, 2022

Hey,

First, thanks for your really useful library!

Is it possible for to connect your phone function with the setLocale function from yup ?

With the set Locale function, i can change all the different languages on one place. But your phone function isn't working.

The native yup functions predefine the error message from the locale definition like:

length( length: number | Reference<number>, message: Message<{ length: number }> = locale.length, ) { .... }
source: https://github.com/jquense/yup/blob/master/src/string.ts

In your case, it is a hard coded string in English (or you change it explicitly when you call the phone function).

regards
Reocin

@csandman
Copy link
Owner

I've never looked into the setLocale function in yup before, can you give me an example of how you'd be using it?

@Reocin
Copy link
Author

Reocin commented Dec 21, 2022

Actually, i don't know much either. As i discovered this package a couple of days ago.

But you hav to get somehow access to the following file.

import { string as locale } from './locale';

Then you can check if here is a phone property like.

def phone(countryCode, errorMess){
  let message = errorMess ? errorMess :  'default error message'
  if(!errorMess && local.phone){
    message = local.phone
  }

}

So the main questions is how to get access to the local file of Yup.

@Reocin
Copy link
Author

Reocin commented Dec 21, 2022

jquense/yup#936

Take a look into this issue. The comment mentions how to import the locale, but it probably won't work out of the box in typescript, as the phone is included in the interface. (Probably thy would have to add a \ ts-ignore somewhere) But at least in javascript would work ;-)

I also recommend following this issue, so you stay updated :-)

@knicola
Copy link

knicola commented Mar 8, 2024

we can now use yup.defaultLocale. I'm trying to add support for this as well in yup-password: https://github.com/knicola/yup-password/pull/16/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants