Trembling input text triggered by a PATCH request

Having a text input box in VueJs for a ticket, I faced an issue with the timer function. When the setTimer(10000) expires while I am still typing in the input box, the page reloads and my input is erased. This interruption lasts only about 3 seconds but it is disrupting my workflow. What would be the most effective way to address this problem?

Snippet of Relevant Code

<b-field label="Description">
        <b-input
            type="textarea"
             v-model="strValue"
            :disabled="waiting.updateAttachment"
        >
        </b-input>
      </b-field>

Javascript Section

 strValue: {
  get: function () {
    return this.attachment.strValue;
  },
  set: function (val) {
   let self = this; setTimeout(function(){ return self.updateAttachment([self.attachment.id, { strValue: val }]) },8000)  },
},

},

Answer №1

To prevent input delay issues, there are various methods you can use. However, upon reviewing your code, it seems like you may not be properly clearing the timeout when updating the input value. To avoid the problem of it over-firing, remember to cancel the timeout function before setting it again after each keypress.

One approach is to keep track of the timeout using a property in your data:

data() {
  return {
    strValue: '',
    inputTimeout: null
  };
}

Then, in your set function:

set: function(val){
  let self = this;
  self.strValue = val;
  clearTimeout(self.inputTimeout);

  self.inputTimeout = setTimeout(function() {
    // include your update attachment function call here
  }, 1000);
}

This essentially means "wait 1 second after the user stops typing before updating the attachment." You could also utilize a watch on strValue and eliminate the explicit getter/setter if that feels more comfortable for you!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible for a function parameter to utilize an array method?

Just starting to grasp ES6 and diving into my inaugural React App via an online course. Wanted to share a snag I hit along the way, along with a link to my git repository for any kind souls willing to lend a hand. This app is designed for book organization ...

The .css() method does not apply any styles to the elements in the document

Having trouble with a jQuery function: .css() This is the HTML code in question: <div class="..." id="about"> // OTHER HTML CODE </div> And here's the corresponding jQuery code: (function($, window, document) { $(function() { ...

Tips for assigning information from a react hook within a function or event

Currently, I am in the process of learning how to create hooks in order to efficiently reuse data that needs to be modified across different components. For my project, I am utilizing Material UI's Tabs and require the use of a custom hook called use ...

Update the package.json file to match the contents found in the node_modules directory

Received a project that was previously in progress by someone else. I noticed that when copying it, the node_modules folder must also be copied for it to function properly. Is there a way to automatically update the package.json file according to the con ...

When working with mongoose, express, node.js, and javascript, sometimes a

function getPassword(uname) { User.findOne({'username': uname},{'password': 1}, function(err, cb) { console.log("print 2"); return cb.password; }); console.log("print 1"); } I'm currently learning ...

asp.net server-side events can intermittently fail to trigger due to conflicts with JavaScript

I am facing what initially seemed like a simple javascript issue, but now I am becoming frustrated trying to solve it. The problem I encountered was with a slow-loading page where users could click the submit button and then another button while waiting f ...

The Angular 2 Router's navigation functionality seems to be malfunctioning within a service

Currently, I am facing an issue with using Angular2 Router.navigate as it is not functioning as expected. import { Injectable } from '@angular/core'; import { Http, Headers } from '@angular/http'; import { Router } from '@angular/ ...

Building File Class in React.js

In my recent project using react.js, I have been focusing on the functionality of uploading multiple files. Upon checking the console.log output, I noticed that it displayed something like [File, File, File] when three files were uploaded. Each "File" obje ...

Vue modifies the array in the data after creating a duplicate of it

Here is the Vue code snippet I'm working with: export default { name: 'Test', data() { return { test1: ['1', '2', '3'], test2: [{ name: 'Hello' }, { name: &apo ...

What is the best way to showcase the outcome on the current page?

This is a sample HTML code for a registration form: <html> <head></head> <body> <form id="myform" action="formdata.php" method="post"> username:<input type="text" name="username" id="name"><br> password:&l ...

What are some techniques for styling the content within a table?

I have a function that dynamically creates tables: function generateTableContent(data) { var table = $('<table id="tblResultsList">'); var tr; var td; $.each(data.d.foundItems, function(i, item) { var button = $(& ...

Tips for successfully incorporating PHP dynamic parameters separated by commas into a JavaScript onclick function

How can I pass PHP dynamic parameters separated by commas to a JavaScript onclick function? Can someone assist me with the correct solution? The code below is not working as expected. echo "<td><a href='#' onclick='editUser(". $row ...

What could be causing my router UI in angular.js to malfunction?

Having an issue with routing not functioning as intended, here is the relevant code: $urlRouterProvider. otherwise('/list'); $stateProvider. state('home', { abstract: true, views: { 'header': { templateUrl: &apos ...

Scroll horizontally based on mouse movement

My angular directive that enables me to choose the content of table cells is performing as expected. However, I encountered an issue when attempting to select multiple cells at once - the scrollbar does not move, hindering my ability to select the cells. ...

Switching from PHP to jQuery or JavaScript can make for a

I've been attempting to convert this PHP code to jQuery or JavaScript without success. I'm still learning about jQuery and JavaScript Check out the original PHP code: <?php // Set timezone date_default_timezone_set('UTC'); ...

How to search for a value in Firebase database and save it to an HTML table?

I am working on fetching specific values from my 'snapshot' and storing them if they exist. Below is the snippet of my code: function paydata(){ firebase.database().ref("pay/0/0/").once('value', function(snapshot){ var resp ...

Creating personalized underlines with gradient functionality in React using an API

I am eager to replicate the Underline Effect demonstrated in this Codepen using React and Typescript The Codepen: https://codepen.io/krakruhahah/pen/jOzwXww It seems like my problem lies within the interface declaration below. I've defined my types, ...

Error in Typescript: Attempting to access the property 'set' of an undefined value

Currently, I am in the process of setting up a basic example of push notifications on Android using Nativescript and Typescript. Although my code may seem a bit messy, I am struggling with properly rewriting "var Observable = require("data/observable");" a ...

Oops! An error occurred indicating that the ES Module is required using the require() function

When running version 13, the terminal displays the following error: Error:const ms = require('parse-ms') // npm i parse-ms ^ Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\DELL\OneDrive\Desktop\Discord Bot&bso ...

How to Align Content in the Center of v-list-tile-content using Vuetify

I've been struggling to center the content within a v-list-tile-content of a v-list. I attempted using text-xs-center, justify-center on both the v-list element and the v-list-tile-content without success. Even inserting an additional div inside the v ...