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

201
Views
VueJS input with v-model accepts only one character

I have this Vue 1 application with a table that has an input for every cell.

The problematic part in particular has 3 fields on a row:

  • dx
  • sx
  • diff

I want that when dx and sx are filled, diff becomes the difference between the two.

To achieve this I set up a watcher for each dx and sx fields that calculates the difference when both corresponding inputs are filled.

'athlete.inputs[testData.edf.abdother.dx.id].comment': function(){
      this.calcDiff('abdother.dx.id')
},

'athlete.inputs[testData.edf.abdother.sx.id].comment': function(){
      this.calcDiff('abdother.sx.id')
},

...
 calcDiff: function(input){
      console.log('calculating diff', this.athlete);
      input = input.split('.')
      var dx = this.athlete.inputs[this.testData.edf[input[0]]['dx'][input[2]]].comment
      var sx = this.athlete.inputs[this.testData.edf[input[0]]['sx'][input[2]]].comment
      console.log({dx, sx})
      if (!dx || !sx)
        return;
      
      this.athlete.inputs[this.testData.edf[input[0]]['diff'][input[2]]].comment = dx >= sx ? dx - sx : sx - dx 
    },

After setting all up I tried changing some values:

  • If I enter one character everything works fine
  • If I enter a second (or more) characters, suddenly the value of the property becomes null

Logged values

As you can see from the picture, if I enter 1 it logs the correct value, but if I enter a second value it becomes null. If I delete all the characters but one then it starts working again.

Setting one character in both inputs works as expected, it calculates the difference and places it in the right place.

More characters immediately unsets the variable and empties the field as soon as you unfocus it.

Any ideas?

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

0

The problem is most likely that String.split() uses regular expressions in JavaScript. Because . is the wildcard in regex, your input.split('.') is splitting on every character. Try adding a backslash before the .

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!