Skip to content

Default values are not loaded in the v-model #3983

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

Open
Rednas83 opened this issue Apr 25, 2025 · 0 comments
Open

Default values are not loaded in the v-model #3983

Rednas83 opened this issue Apr 25, 2025 · 0 comments
Labels
bug Something isn't working triage v3 #1289

Comments

@Rednas83
Copy link

Environment

Is this bug related to Nuxt or Vue?

Nuxt

Version

v3.1.0

Reproduction

<template>
  <div class="flex">
    <UForm :state="state" class="w-1/2 p-4">
      <UFormField v-for="(item, index) in items" :key="index" :label="index" :name="index">
        <UColorPicker v-if="index == 'color'" v-model="state[index]" :default-value="item" />
        <USlider v-if="index == 'range' && typeof item == 'number'" v-model="state[index]" :default-value="item" />
        <UInput v-if="typeof state[index] == 'boolean'" :type="index" :value="index" :checked="item" />
        <UInput v-else :type="index" v-model="state[index]" :default-value="item" />
      </UFormField>
    </UForm>
    <pre class="w-1/2 bg-gray-200 p-4 leading-14"> {{ state }} </pre>
  </div>
</template>

<script lang="ts" setup>
const state = ref({}) // ISSUE: Default values are not loaded in the v-model
const items = {
  number: 50,
  reset: true, // ISSUE: UInput is not supporting boolean values for v-model
  submit: true, // ISSUE: UInput is not supporting boolean values for v-model
  search: "search",
  date: "2025-04-25",
  text: "text",
  color: "#ccffcc",
  button: true, // ISSUE: UInput is not supporting boolean values for v-model
  checkbox: false, // ISSUE: UInput is not supporting boolean values for v-model
  "datetime-local": "2025-04-25T10:49:31",
  email: "[email protected]",
  file: "",
  hidden: "hidden",
  image: "image.svg",
  month: "2025-04",
  password: "topsecret",
  radio: true, // ISSUE: UInput is not supporting boolean values for v-model
  range: 50, // Default value is displayed but not loaded in the v-model
  tel: "0612345678",
  time: "10:49:31",
  url: "www.chatgpt.com",
  week: "2025-W16"
}
// const state = reactive(items) // Workaround for default-value
</script>

Description

I made a small comparison between UInput and other components like UColorPicker and USlider and I stumbled on a couple of issues.

  • default-value is not displayed except for range and USlider
  • default-value is never initialized in the v-model
  • Booleans are not supported in the v-model and I was therefore not able to make them reactive.

Workaround is to load the default value via the state, but that requires an additional step and is therefore not ideal for dynamic forms
const state = reactive(items)

Workaround for working with booleans, but I am not sure how to apply the v-model yet🤔
<UInput v-if="typeof state[index] == 'boolean'" :type="index" :value="index" :checked="item" />

Additional context

Default values via default-value
Image
Default value via state
Image

Logs

@Rednas83 Rednas83 added bug Something isn't working triage v3 #1289 labels Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage v3 #1289
Projects
None yet
Development

No branches or pull requests

1 participant