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

password() message #7

Closed
kgrigorian opened this issue Jun 2, 2022 · 5 comments
Closed

password() message #7

kgrigorian opened this issue Jun 2, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@kgrigorian
Copy link

.password() method does not take message argument (other method do have it)

@knicola knicola added the enhancement New feature or request label Jun 2, 2022
@knicola
Copy link
Owner

knicola commented Jun 2, 2022

the .password() is mostly a convenience method, if you will, with reasonable defaults. it doesn't make much sense to me to add options to customize its behavior when you can either chain the rule you want to customize (ie .password().minLowercase(1, 'custom message') or replace .password() completely with the rules you think is best for your use case.

however, if more people would like this option I will not object to it.

two variations come to mind:

// 1st option
.password({
  messages: {
    minLowercase: 'custom message',
    minUppercase: 'custom message',
    ...
  },
  rules: {
    minLowercase: 2,
    minUppercase: 3,
    ...
  },
})
// 2nd option
.password({
  minLowercase: [2, 'custom message'],
  minUppercase: [2, 'custom message'],
  ..
})

also lets compare it to this:

.password().minLowercase(2, 'custom message').minUppercase(3, 'custom message')

additional ideas are welcome

@knicola
Copy link
Owner

knicola commented Jun 14, 2022

closing this ticket for now. if anyone thinks this is a useful option to have and/or have any additional ideas please drop them here and will reopen the ticket for discussion.

@knicola knicola closed this as completed Jun 14, 2022
@MadhawaS96
Copy link

MadhawaS96 commented Sep 5, 2024

Just a tiny issue, maybe I missed this in the docs. Say I have a field name as "currentPassword". The returned error message would be displayed as ie: "currentPassword must contain at least 1 uppercase letter".

Do you have any option to change the name set into the error message? I hope the description explains the issue clearly.

Let me know if you prefer this to be opened as a new issue. Tagged here since I thought this can be related to the current topic.

Thanks!

@knicola
Copy link
Owner

knicola commented Sep 5, 2024

@MadhawaS96 you can use Schema.label()

const schema = yup.object().shape({
    currentPassword: yup.string().password().required().label('Current password'),
})

@MadhawaS96
Copy link

@MadhawaS96 you can use Schema.label()

const schema = yup.object().shape({
    currentPassword: yup.string().password().required().label('Current password'),
})

Brilliant! Thank you so much for both the answer and your quick response. Much appreciated!

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

No branches or pull requests

3 participants