jquense / yup

Dead simple Object schema validation
MIT License
22.93k stars 934 forks source link

Get the label of a referenced field in `setLocale()` #2109

Open alinnert opened 1 year ago

alinnert commented 1 year ago

In setLocale() I'm trying to create an error message for a field whose value needs to be equal to the value of another field. Technically "password" and "password confirm".

I have the following code so far:

setLocale({
  mixed: {
    oneOf: ({ label, values }) => $t('yup-field-must-be-one-of', { field: label, otherField: values }),
  },
})

I've looked into all possible values of the parameter. There I have access to the value of the referenced field as well as to the term ref(<name of the referenced field>).

If I want to create a wording for the password confirm field like "The value of this field must match that of the field Password." I'd need access to the label of the referenced field which I currently don't seem to have.

Is there a way to do this now or could that value please be added to the parameter object?

Maxime-p commented 10 months ago

I'm also interested