nuxt / ui

A UI Library for Modern Web Apps, powered by Vue & Tailwind CSS.
https://ui.nuxt.com
MIT License
4.14k stars 553 forks source link

UFormGroup don't display error form v-calendar DatePicker #1717

Closed EvanSchleret closed 7 months ago

EvanSchleret commented 7 months ago

Environment

Version

v2.14.1

Reproduction

https://stackblitz.com/edit/nuxt-ui-jbdest?file=app.vue

Description

I tried for a while yesterday to use the DatePicker component of V-Calendar, highlighted in the Nuxt UI doc (https://ui.nuxt.com/components/date-picker).

The need I have is simple: two date selectors (of type dateTime) to specify a start date and another end date, in a UForm. So far, you might say, nothing crazy. Then, I wanted to add validation with yup, also highlighted in the Nuxt UI doc.

Yup validation works (I tried many ways, did some debugging to see if the validation worked well). It is therefore - a priori - not on that side.

Additional context

With datetime-local type in UInput field, it works.

Logs

No response

romhml commented 7 months ago

Validation on input events are not supported for components outside of Nuxt UI but can be implemented.

In your example, the validation will be triggered only when the form is submitted: https://stackblitz.com/edit/nuxt-ui-pzguv9?file=app.vue

To implement validation when the input changes, you have to implement a wrapper around the VCalendar component that will emit an event back to the Form when the value changes. You can use the useFormGroup composable to do so. Here's an example implementation:

https://stackblitz.com/edit/nuxt-ui-kdi8ka?file=components/BaseDatePicker.vue

romhml commented 7 months ago

@EvanSchleret I just updated the last example link, I got mixed up with another reproduction.

EvanSchleret commented 7 months ago

Thank you very much for taking this time to show me exactly how to do it :) I'll think about whether it's useful to propose this kind of modification to the v-calendar repo. It might interest other people I suppose !

Have a great end of week

fmarcheski commented 6 months ago

Validation on input events are not supported for components outside of Nuxt UI but can be implemented.

In your example, the validation will be triggered only when the form is submitted: https://stackblitz.com/edit/nuxt-ui-pzguv9?file=app.vue

To implement validation when the input changes, you have to implement a wrapper around the VCalendar component that will emit an event back to the Form when the value changes. You can use the useFormGroup composable to do so. Here's an example implementation:

https://stackblitz.com/edit/nuxt-ui-kdi8ka?file=components/BaseDatePicker.vue

This solved it for me. Thanks!