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

[Docs] $emit('input', value) cancels event.preventDefault() #13108

Closed
Madyuskin opened this issue Oct 25, 2023 · 1 comment
Closed

[Docs] $emit('input', value) cancels event.preventDefault() #13108

Madyuskin opened this issue Oct 25, 2023 · 1 comment

Comments

@Madyuskin
Copy link

What problem does this feature solve?

I believe this behavior should be mentioned in the docs.

<v-text-field
  :value="value"
  ref="textField"
  @input.native="textFieldInput"
/>
textFieldInput(event) {
  let value = event.target.value

  if (event.inputType === 'insertFromPaste') {
    event.preventDefault()

    value = value.replace(...)

    // this.$refs.textField.$refs.input.value = value
  }

  this.$emit('input', value) // Cancels the above event.preventDefault()
}

What does the proposed API look like?

Just use a different name for the event

textFieldInput(event) {
  let value = event.target.value

  if (event.inputType === 'insertFromPaste') {
    event.preventDefault()

    value = value.replace(...)

    // this.$refs.textField.$refs.input.value = value

    this.$emit('input-paste', value)
  } else {
    this.$emit('input', value)
  }
}
<CustomTextField
  v-model="value"
  @input-paste="_value => value = _value"
/>
@posva
Copy link
Member

posva commented Oct 25, 2023

Open a PR to https://github.com/vuejs/v2.vuejs.org with the proposal. Thanks!

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants