Skip to content
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

Allow to pass an object of modelModifiers to native inputs #8281

Open
Fuzzyma opened this issue May 11, 2023 · 3 comments
Open

Allow to pass an object of modelModifiers to native inputs #8281

Fuzzyma opened this issue May 11, 2023 · 3 comments
Labels
✨ feature request New feature or request

Comments

@Fuzzyma
Copy link

Fuzzyma commented May 11, 2023

What problem does this feature solve?

Native inputs support v-model modifiers lazy, number and trim.
However, most of the time, people use a wrapper around their inputs.

According to the docs you can add modelModifiers to your custom component so thats not the problem.
However, it is impossible to pass all modifiers from the wrapper component down to the unerlying native input.

<template>
  <!-- not working -->
  <input v-model.modelMofidiers="value" />
</template>

<script setup>
defineProps({
  modelValue: String,
  modelModifiers: Object
})
</script>

There is just no working syntax.

What does the proposed API look like?

<template
  <input v-model.[modelModifiers]="value" />
</template>
@Fuzzyma Fuzzyma added the ✨ feature request New feature or request label May 11, 2023
@JontyMC
Copy link

JontyMC commented May 7, 2024

+1 for this, seem odd in order to simply wrap an input and provide support for .lazy you need to this:

<script setup lang="ts">
import { defineModel } from 'vue'

const [model, modifiers] = defineModel<string>()

function input(event: Event) {
  if (modifiers.lazy) {
    return
  }
  model.value = (event.target as HTMLInputElement).value
}

function change(event: Event) {
  if (!modifiers.lazy) {
    return
  }
  model.value = (event.target as HTMLInputElement).value
}
</script>

<template>
  <input :value="model" type="text" @input="input" @change="change" />
</template>

@Magentai
Copy link

Are there some updates on this issue?
There's no nice way to build nested component with model modifiers because of this.

@ReturnMeVoid
Copy link

Are there some updates on this issue? There's no nice way to build nested component with model modifiers because of this.

@Magentai unfortunately not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature request New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants