I've got a bit of an add situation with a custom "Edit In Place" Vuetify text input. I noticed that on keyup of the enter key, there were two requests being made to my backend to update the field. I know what's causing the issue, just not sure how to fix it!
I have this text field:
<v-text-field
:id="uniqueIdentifier"
:ref="uniqueIdentifier"
v-focus
v-mask="mask"
:class="[ 'click-to-edit', active ? 'active' : 'b-none', customClass ]"
color="primary"
dense
:full-width="false"
hide-details
outlined
:style="{...customStyle}"
:type="type"
:value="localValue"
@blur="handleUpdateItem($event)"
@click="activateInput"
@keyup.enter.native="handleUpdateItem($event)" />
As you can see, I have both @blur and @keyup.enter.native events being fired to update the text field. The method to update the field looks like this:
handleUpdateItem (e) {
this.localValue = e.target.value;
this.active = false;
this.$emit('handle-update-item', this.localValue);
// if (e.type === 'keyup') { this.$refs[this.uniqueIdentifier].blur(); }
// if (e.type === 'keyup') { this.active = false; }
}
The two last lines of that method that are commented out are my attempts, and are intended to "deactivate" the input on click of enter, however because the first line is then running .blur(), the text field runs this function a second time. The second line still has the blinking cursor in the input, so it's not really "deactivated" either.
Ultimately what I'm looking for is a way to allow the user to either press enter or click outside of the input to fire off the request (obviously without it firing twice) and deactivate the input. Does anyone have a suggestion?