unovue / shadcn-vue

Vue port of shadcn-ui
https://www.shadcn-vue.com/
MIT License
5.15k stars 301 forks source link

[Bug]: Auto Form toDate is not a function when form schema has default value #780

Open LeclechM opened 1 month ago

LeclechM commented 1 month ago

Reproduction

https://stackblitz.com/edit/nuxt-vue-3-4-beta-twkyrr?file=src%2Fpages%2Fhome%2FHomePage.vue

Describe the bug

In documentation:

If you want to set default value of date, convert it to Date first using new Date(val).

An error occurs during {{ slotProps.componentField.modelValue ? df.format(slotProps.componentField.modelValue.toDate(getLocalTimeZone())) : "Pick a date" }}

because slotProps.componentField.modelValue is of type string and not a DateValue like expected by Calendar component.

System Info

System:
    OS: Linux 6.8 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-1235U
    Memory: 2.89 GB / 15.30 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
    pnpm: 9.10.0 - ~/.local/share/pnpm/pnpm
    bun: 1.1.27 - ~/.bun/bin/bun
  Browsers:
    Chrome: 129.0.6668.58

Contributes

Keiishu commented 1 week ago

That's because radix-vue's Date Picker uses @internationalized/date only. I'm facing the same issue. I can't set initial values because of that, and Zod doesn't support such objects.