-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
label
field doesn't take precedence over name
when used with useField
#4268
Comments
Your expectation is correct, however this test actually tests that use-case. All the tests use Can you please create a sample that reproduces this with either codesandbox or stackblitz? Will make it faster for me to debug and fix. |
Thanks for the fast answer !! Understood for the use case you mentioned. I got confusing because the test here use test('it should fetch label message when label is set as option in useField', async () => {
let errorMessage!: Ref<string | undefined>;
configure({
generateMessage: localize('en', {
messages: { required: '{field} is required' },
names: {
first: 'First test',
labelFirst: 'Label First test',
second: 'Second test'
},
}),
});
mountWithHoc({
setup() {
const field = useField('first', 'required', { validateOnMount: true, label: 'labelFirst' });
errorMessage = field.errorMessage;
},
template: `
<div>
</div>
`,
});
await flushPromises();
expect(errorMessage.value).toBe('Label First test is required');
}); But well noted, I will try to create a sample that reproduces this with either codesandbox or stackblitz. Thanks |
Hi @logaretm, I created a sample that reproduces this with codesandbox here so please have a look. I tried to reproduce my environment as much as possible. It is a Quasar app in vue 3 + Vee validate 4.9 + Vite 2.9. So here is the situation Case 1 (it doesn't work): // src/pages/IndexPage.vue
vee-validate-input(
:label="$t('mixin.form.email')"
localize="mixinEmail"
name="email"
rules="required"
type="email"
) and you set // src/components/shared/v-validate/input.vue
const { errorMessage, resetField, value } = useField(
this.name,
this.rules,
{
initialValue: this.initialValue,
keepValueOnUnmount: this.keepValueOnUnmount,
label: this.localize ? this.localize : null
}
) I got Case 2 (it works) // src/pages/IndexPage.vue
vee-validate-input(
:label="$t('mixin.form.email')"
localize="mixinEmail"
name="mixinEmail"
rules="required"
type="email"
) and you comment out // src/components/shared/v-validate/input.vue
const { errorMessage, resetField, value } = useField(
this.name,
this.rules,
{
initialValue: this.initialValue,
keepValueOnUnmount: this.keepValueOnUnmount,
// label: this.localize ? this.localize : null
}
) It works, I got メールアドレスは必須項目です. This is because So could you could have a look to case 1 to make it work again please ? Let me know if you need more information. Thanks ! |
That is expected. the If you are using i18n then do not use Do you think this is confusing? I will think about it before I close this issue, maybe this should be a supported behavior. |
Well, this behavior was working before, that's why I actually implemented my code this way. So it would be great to have this behavior back again. The reason I like this feature is that I can keep my names clean in So if you think the implementation is not that hard, having this feature again would be good. |
Right, I had no idea it worked before. I think it broke in some recent fixes around that area because it was never intended. But I guess we can re-introduce it officially with a test case. Should be released with the next patch. |
What happened?
When using
useField
withlabel
in options, it is ignored. For examplegenerateMessage
is defined like thisThe API reference here says the following explanation for
label
A friendly name to be used in generateMessage config instead of the field name, has no effect with yup rules
So I expect label to take precedence over name. But currently it is ignored (I don't use yup). I just got a message saying
mixinEmail is required
.I read this thread here which look similar but it doesn't handle the case where we set label as option in useField.
I also had a look to test cases here
and there is no test to verify that label should take precedence over name when both (name and label) are set in useField.
Btw, it was working before, I just discovered that I got the key in the error message instead of the sentence defined in
generateMessage
.Am I missing something ?
Thanks !
Reproduction steps
email
useField
and set label withlabel :'mixinEmail'
in the optionsmixinEmail
as names in generateMessage.Version
Vue.js 3.x and vee-validate 4.x
What browsers are you seeing the problem on?
Relevant log output
Demo link
Here
Code of Conduct
The text was updated successfully, but these errors were encountered: