-
Notifications
You must be signed in to change notification settings - Fork 880
Closed
Labels
Description
Environment
- Operating System: Darwin
- Node Version: v23.5.0
- Nuxt Version: 3.17.6
- CLI Version: 3.25.1
- Nitro Version: 2.11.13
- Package Manager: [email protected]
- Builder: -
- User Config: devtools, typescript, modules, css, future, compatibilityDate
- Runtime Modules: @nuxt/[email protected], @nuxt/[email protected]
- Build Modules: -
Is this bug related to Nuxt or Vue?
Nuxt
Version
v3.2.0
Reproduction
https://github.com/harkor/nuxt-ui-form-errors-reproduction
Description
If I write this
formRef.value?.setErrors([
{
name: "pathForACustomError",
message: "This is a custom error message.",
},
]);
The error will be set in formRef?.getErrors('pathForACustomError')
But if I watch a state like this and clear the error
watch(
() => state.hello,
() => {
console.log("Hello changed:", state.hello);
formRef.value?.clear("pathForACustomError");
},
);
If the UFormField component have a name (the component change the value), formRef?.getErrors('pathForACustomError') will not be cleared, it will for 1 or two tick but after that, the error is still there.
In my reproduction you have 3 URadioGroup
Hello, World and Hi
If you change
- "Hello", error not cleared
- "World", error cleared
- "Hi", error cleared
What change between these 3 fields
- "Hello" have a name attribute in the UFormField
- "World" don't have a name attribute in the UFormField
- "Hi" have a name in attribute BUT with a @change will clear "again" the error
PS: Don't forget to click on "Set custom error" button before change values on URadioGroup's components
Bonus: Since version 3.2.0, I have a typescript error for getErrors(path) with typecheck enabled
Expectations
- First UFormField "hello" clear the error when state change with a watch
- No typescript error on getErrors
Additional context
No response
Logs
ERROR 11:39:08 AM
ERROR(vue-tsc) Argument of type '"pathForACustomError"' is not assignable to parameter of type 'undefined'.
FILE /home/projects/xoriallzvx.github/app/components/MyForm.vue:127:36
125 | </UFormField>
126 | <div
> 127 | v-if="!!formRef?.getErrors('pathForACustomError').length"
| ^^^^^^^^^^^^^^^^^^^^^
128 | class="text-red-400"
129 | >
130 | {{ formRef?.getErrors("pathForACustomError")[0]?.message }}
ERROR(vue-tsc) Argument of type '"pathForACustomError"' is not assignable to parameter of type 'undefined'.
FILE /home/projects/xoriallzvx.github/app/components/MyForm.vue:130:29
128 | class="text-red-400"
129 | >
> 130 | {{ formRef?.getErrors("pathForACustomError")[0]?.message }}
| ^^^^^^^^^^^^^^^^^^^^^
131 | </div>
132 | </UForm>
133 | </template>
[vue-tsc] Found 2 errors. Watching for file changes.