Vuetify: [Enhancement] v-combobox does not update until blur

Created on 21 Jul 2018  路  23Comments  路  Source: vuetifyjs/vuetify

(Possibly unrelated) v-combobox does not seem to emit "input" events, only "update:searchInput".
I tried to use with v-debounce but it did not work.

I have a v-combobox in a v-form, it is a required field with rules. I want to be able to type in the combobox and see that the validation errors disappear and the submit button is enabled without clicking outside of the combobox

https://codepen.io/nalbion/pen/xJgYjL?editors=1111

VCombobox enhancement has workaround

Most helpful comment

Possible workaround
https://codepen.io/thexperiments/pen/ywOdwe

@input.native="category=$event.srcElement.value"

where category is the same model attached to the v-model of the combobox.
Would still like it more if it was generic and I could just add this to all the comboboxes without modifying to point to the right model.

All 23 comments

i think combobox makes validation on change event, that's why.

I think that's bad UX. It should be possible for the app developer to choose when to validate

imho combobox should just emit @input while typing but it extends v-autocomplete so probably won't be a simple fix

Is there a way to update the v-model as soon as you start typing and to be able to search though the selection box?

No, that's what this issue's for.

Any workaround until this is fixed?

you can use the native input event

<v-combobox :items="$store.state.models.map(item => item.fullName)"
                            @input="setFilterString"
                            @input.native="setFilterString"></v-combobox>
setFilterString (e) {
      if (!e) {
        this.filterString = ''
      } else if (typeof e === 'string') {
        this.filterString = e
      } else if (typeof e === 'object') {
        this.filterString = e.srcElement.value
      }
    },

Hitting the same issue here.
My combobox is last in the form and thus when submitting the form it is very likely that it has not blurred yet and thus the value was not propagated to the property yet.

Additional ideas for a workaround?

https://codepen.io/thexperiments/pen/GeZbxX this demonstrates the issue

Possible workaround
https://codepen.io/thexperiments/pen/ywOdwe

@input.native="category=$event.srcElement.value"

where category is the same model attached to the v-model of the combobox.
Would still like it more if it was generic and I could just add this to all the comboboxes without modifying to point to the right model.

@input.native="category=$event.srcElement.value"

This works for disregarding the onblur, but it prevents the combobox from filtering through the object list as I type now. Has anyone solved this added problem?

Problem still unsolved a year later, however the above workaround does work.

I have another UGLY workaround. I cannot use input.native since I'm using multiple chips with items containing array of objects {text..., value...}.

<v-form ... @submit="form_submit"> ...
...
form_submit: function(event) {
  // XXX: Allow background value update to complete first. (e.g. Combobox).
  //      See https://github.com/vuetifyjs/vuetify/issues/4679
  setTimeout(() => {
    // Actual form submission here.
  }, 100);
},

Simply allow blur event to run before submit. Ugly, but seem working fine. Hopefully this helps.

I'm very interested in seeing this get fixed. I would like to use the events to track inputs to the field in real time while still being able to use the built-in filtering. Can't do that right now as this component currently is.

Workaround (updated to Vuetify 2.x) https://codepen.io/jkarczm/pen/pooOOjV?editors=1111 (same as #5203)

@jacekkarczmarczyk are you sure this workaround still works...? There is no update on input change?

I created a workaround myself. Please see this CodePen: https://codepen.io/Paulsky/pen/PowEZOE

I'm using the '$refs' to get the 'internalSearch' of a dummy model, and set the 'actually' model. The '@ change' is a little misleading; this is only fired when a item from the list is chosen by the user.

Hope this helps someone.

By the way: You could use something like https://lodash.com/docs/latest#debounce to not fire the onChange function directly on each input

Would love to see a fix for that as well. For now, requesting an animation frame seemed to do the trick for us, since relying on input.native would trigger validation rules too early.

I seem to have found a workaround as well. It's less hacky than the others suggested here. I don't think this one has any side effects like broken filtering or delays either.

<template>
    ...
    <v-combobox id="targetInput"
                @update:search-input="updateTargetInput" 
                :rules="rules" 
                :items="autocompletes"
                ></v-combobox>
    ...
</template>

<script>
    ...
    data() {
        return {
            currentTargetInput : null
        }
    },
    methods: {
        updateTargetInput(){
            this.currentTargetInput = document.getElementById("targetInput").value
        }
    }
    ...
</script>

Turns out that the filtering issue goes away if you don't set a v-model on the component directly.

I seem to have found a workaround as well. It's less hacky than the others suggested here. I don't think this one has any side effects like broken filtering or delays either.

<template>
    ...
    <v-combobox id="targetInput"
                @update:search-input="updateTargetInput" 
                :rules="rules" 
                :items="autocompletes"
                ></v-combobox>
    ...
</template>

<script>
    ...
    data() {
        return {
            currentTargetInput : null
        }
    },
    methods: {
        updateTargetInput(){
            this.currentTargetInput = document.getElementById("targetInput").value
        }
    }
    ...
</script>

Turns out that the filtering issue goes away if you don't set a v-model on the component directly.

When user selects an item from the autocomplete list, currentTargetInput is not getting updated, but rest everything is working
@SameeranB

@nvspradeep
Adding the @update:list-index might work. I haven't tried it though...

@SameeranB Problem resolved!! , I have assigned the value emitted from @ update event directly , instead of doc.getElementbyId.value, Somehow it is working!! thanks!

<template>
    ...
    <v-combobox id="targetInput"
                @update:search-input="updateTargetInput" 
                :rules="rules" 
                :items="autocompletes"
                ></v-combobox>
    ...
</template>

<script>
    ...
    data() {
        return {
            currentTargetInput : null
        }
    },
    methods: {
        updateTargetInput(currentValue){
            this.currentTargetInput = currentValue
        }
    }
    ...
</script>

@PradeepNooney... Thank YOU! Finally... It works...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smousa picture smousa  路  3Comments

cawa-93 picture cawa-93  路  3Comments

aaronjpitts picture aaronjpitts  路  3Comments

KuroThing picture KuroThing  路  3Comments

alterhu2020 picture alterhu2020  路  3Comments