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

269
Visualizações
Can't change input value from javascript but working from chrome debugger console

Recently I am facing a strange issue while using https://github.com/Shopify/draggable package. So here is the problem, I am using stimulus js in rails app, and in one of the stimulus controllers I have:

export default class extends ApplicationController {
 updateElementPosition(target) {
  let positions = target.querySelectorAll('input[name="position"]');
  positions.forEach(positionInput => {
   const index = this.index(positionInput.closest('[element]'))
   positionInput.value = index
  })
 }
 .... in one function
 registerEvent() {
   sortable.on('drag:stopped', function(event) {
    let oldStep = $(event.sourceContainer).parents('[step]')[0]
    let newStep = $(event.originalSource).parents('[step]')[0]
    if (oldStep == newStep) {
     this.updateElementPosition(newStep)
    } else {
     this.updateElementPosition(oldStep)
     this.updateElementPosition(newStep)
    }
  }.bind(this))
 }
}

So basically I want to update an element position input value whenever an element is dragged to a different position inside a draggable container.

Problem: When I use the debugger in updateElementPosition and execute each line by line then the positionInput value is set properly, but when I run it as it is, then it does not set the positionInput with the index value.

about 4 years ago · Juan Pablo Isaza
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