Debouncing form inputs in VueJS with LoDash debounce on the entire form

I'm currently experimenting with implementing LoDash debounce to detect when a user stops typing on a form and trigger an event accordingly.

Looking for inspiration from this helpful guide

However, my goal is to extend this functionality to cover all form/model properties.

Unfortunately, the debounce function does not seem to be activating as intended at the moment.

Check out this example JS Fiddle for reference

JS

    new Vue({
  el: "#app",
  data() {
    return {
      form: {
        user: {
          name: "Bob",
          email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c195a4b2b581b5a4b2b5efa2aeac">[email protected]</a>"
        }
      },
      isTyping: false,
      isLoading: false,
    }
  },
  watch: {
    form: _.debounce(function() {
      this.isTyping = false;
    }, 1000),
    isTyping: function(value) {
      if (!value) {
        console.log("stopped typing")
      }
    }
  },
  methods: {

  }
})

HTML

<div id="app" class="container-fluid">
  <div class="row">
    <div class="col-md-3">
      <label class="control-label">Name</label>
      <input type="text" class="form-control" @input="isTyping = true" v-model="form.user.name" placeholder="Type your keyword">
       <label class="control-label">Email</label>
      <input type="text" class="form-control" @input="isTyping = true" v-model="form.user.email" placeholder="Type your Email">
    </div>
  </div>

</div>

Answer №1

Ensure your observer is set to deep

   watcher: {
      handler: _.throttle(function() {
        this.isWatching = true;
      }, 800),
      deep: true
    },

View updated fiddle here

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

The scope in AngularJS fails to detect changes

One common issue I encountered involved the $scope field used for the ng-src attribute within an <img>: $scope.imageDataUrl To initialize this field, I utilized the following code: $scope.myJsWrapper = new MyJsWrapper(); $scope.myJsWrapper.getImag ...

Enhance with Laravel combined with AngularJS

I've encountered some issues with the "edit" part while working on a Laravel + AngularJS CRUD application. An internal server error is being displayed, and I'm seeking assistance to understand its cause. Error "GET localhost/crudtcc/public/ap ...

Vue chart not displaying data until the window is resized

I've encountered an issue with my apexchart where the data is not displayed when the page loads. It only appears when I zoom in/out or resize the window, which seems odd to me. I came across a similar problem on the apexcharts github, but it doesn&apo ...

Best practices for incorporating packages in Vue.JS SPA applications

Currently, in my vue-cli/webpack project, I have been incorporating new packages using the command: yarn add <package> --dev These packages are stored in the package.json file under devDependencies. While the setup works smoothly, the build process ...

The first parameter in Vue router is optional

Is there a way to make the first parameter in my list of routes optional? I want the parameter to change a header in my api calls if it's present in the url, but everything else should stay the same. Instead of creating two sets of routes to handle t ...

Some suggestions for updating two div elements using only one Ajax response

My website features a signin() button that I want to enhance with ajax functionality. When the button is clicked, I need it to update two divs: one displaying a personalized welcome message, and the other showcasing a statistics table in a different locati ...

Getting the return value from a confirm box in ASP.NET C#

Despite reading through numerous similar questions and answers, I am still unable to find a solution to my problem. I am working on a form that allows users to select a file and choose a date for importing the file. If the selected date is before the last ...

Using React Native, you can easily apply styles to View components by passing them

Is it a bug? Or is the View styles props object supporting inline props as well? For example, in the traditional way and also written in React Native documentation: function App() { return ( <View style={styles.box}></View> ) } const ...

Progress bar display not available

I have recently developed a JavaScript quiz application and included a progress bar feature. While it works flawlessly offline on my laptop, I encountered an issue when uploading the files to Codepen.io - the progress bar fails to display. I would appreci ...

Error Encountered: Unable to locate the variable "Login"

I encountered this rejection error It all started to go wrong in "Routes.js": import React, {Component} from 'react'; import {Router, Stack, Scene} from 'react-native-router-flux'; export default class Routes extends Component<{ ...

Storing user input in an array with the use of JavaScript

Hey everyone, I'm new to JavaScript and have been struggling with a task that seems simple. I'm trying to store user input in an array and then display it in a specific div (eventually I want to create a table using the DOM and store the input th ...

Using populate in the server-side code can result in objects with keys {_id, name} being invalid as a React child

Encountering the error "Uncaught Error: Objects are not valid as a React child (found: object with keys {_id, name})" when using populate in server-side code. However, removing the populate resolves the issue. How can this problem be solved? Here is the sn ...

Unusual issue encountered when launching an express application in node.js

Starting my app is easy with nodemon - just type nodemon However, I encountered an error when trying node app.js https://i.sstatic.net/rRXhZ.png I have checked my package.json and it is properly configured with: "scripts": { "start": "node ./bin/ww ...

The Angular modal service is failing to show up on the screen

I am having trouble implementing the angular modal service in my web application. When I click on the button, the modal does not appear. Can someone help me figure out what I am doing wrong? Builder View <div ng-controller="BuilderController as vm"> ...

How to set the initial speed of a jQuery fadein animation

I'm looking to optimize the loading process of this div on page load so that it displays instantly and then refreshes automatically every 10 seconds. Currently, it refreshes every 10 seconds but I would like it to load instantly as well. Is there a ...

What steps can I take to direct mobile visitors to the mobile-friendly version of my website?

Looking for a way to automatically redirect users on mobile devices from www.domain.com to the new mobile version at m.domain.com? ...

What is the best way to incorporate easing into your scroll animations for a polished

Looking for a way to enhance the smooth scrolling effect in my script, I decided to experiment with adding easing: $('a[href*="#"]') .not('[href="#"]') .not('[href="#0"]') .click(function(event) { if ( locatio ...

Leverage the power of Angular's route resolve function

Can anyone assist me with a problem I'm facing? I am looking for a way to delay the display of a view until my data is loaded. After some research, I was thinking of using a resolve in the route, but I can't seem to figure out how to implement it ...

magnificPopup experiencing difficulties when attempting to invoke a class that is dynamically generated within the HTML document

Currently, I am encountering an issue with the magnificPopup. Whenever I try to trigger the popup using the class 'popup-with-zoom-anim', it doesn't seem to work as expected. Has anyone else faced a similar problem before? <body> < ...

Tips for manipulating a shape and adjusting the vertices later in three.js

Greetings and thank you in advance for your assistance! I have been facing challenges when creating shapes with the mouse using THREE.Shape. While I am able to draw and edit shapes that are centered on the canvas without any issues, I encounter problems wh ...