Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

318
Views
How to disable button if multiple form inputs do not change in Vue.js

I have multiple forms created from API. For each form, I need to check if the value of inputs is changed or not; so that I can make the button disabled or enabled.

So, I tried to create a flag: isChanged: false, so that, I can make the button like this:

<v-btn
  :disabled="!isChanged"
>
  Save
</v-btn>

But, as I have multiple forms, I need to create multiple flags maybe, but I don't understand how to create multiple flags dynamically for each form.

Also, I have a Save All button which may require a new flag such as isChangedAny: false to detect if any of the multiple forms changed or not.

If any of the form inputs change, that button needs to be enabled from disabled. But, most importantly, I can't figure out how to create a method to detect if the form inputs change or not. How can I do that?

CodePen Demo

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You essentially have two options on how to solve this:

  1. You listen to the @input event on a form field, once that fires you set a hasChanged to true. This is the easy solution but it will not work if the user changes the value back to its original, because then the hasChanged is still true and the form is still savable.
  2. Create a copy of the original form data in the mounted() hook and compare the current input with the original input through a computed property. This will work the best but might be a bit more difficult to implement.
about 4 years ago · Juan Pablo Isaza Report

0

You could create individual watchers for each form after you get the data, and store the id of changed forms:

  data: () => ({
    items: [],
    changed: []
  }),
  mounted () {
    this.getData()
    // The following code should be run in a callback when the getData() is asynchronous. 
    this.items.forEach((_, index) => {
      this.$watch(['items', index].join('.'), 
        {
          deep: true, 
          handler: (newVal, oldVal) => {
            this.changed.push(newVal.id)
          }
        }
      );
    });
  }

Then check against the changed array. If a specific id is in that array, activate the form. If the length of changed array is greater than 0, activate saveAll.

Here is the working codepen

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!