Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda