Update input value with Bootstrap touchspin

Asked

Viewed 43 times

0

I’m used a input "quantity" which multiplies the value of the input "unit value" and updates the input "total value". So far working all right.

So I started using the bootstrap-touchspin :

inserir a descrição da imagem aqui

<input type="number" name="p_t11" id="P1103_QTDE" value="1" size="30" maxlength="4000">
    
<input type="text" name="p_t13" id="P1103_TOTAL" value="100,00" size="30" maxlength="4000">


 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.js"></script>

$("input[id='P1103_QTDE']").TouchSpin({
  min: 0,
  max: 10000000000,
  boostat: 5,
  forcestepdivisibility: "none",
  step: 1,
  maxboostedstep: 10,
  buttondown_class: "btn btn-ciano btn-xs btn-mob",
  buttonup_class: "btn btn-ciano btn-xs btn-mob",
  mousewheel: "true"
});

The input "total" does not dynamically update the value on the screen, but saves the value correctly. How could I update the "total value" field dynamically by clicking on the "+" and "-" ?

1 answer

1


You must track the event change which happens in the input to which the bootstrap-touchspin is associated.

You can do it like this:

$("#P1103_QTDE").TouchSpin({
  min: 0,
  max: 10000000000,
  boostat: 5,
  forcestepdivisibility: "none",
  step: 1,
  maxboostedstep: 10,
  buttondown_class: "btn btn-ciano btn-xs btn-mob",
  buttonup_class: "btn btn-ciano btn-xs btn-mob",
  mousewheel: "true"
});

// daqui para baixo é o que precisas
$("#P1103_QTDE").on('change', function() {
    $('#P1103_TOTAL').val(($(this).val()*100).toFixed(2));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.js"></script>

<input type="number" name="p_t11" id="P1103_QTDE" value="1" size="30" maxlength="4000">
    
<input type="text" name="p_t13" id="P1103_TOTAL" value="100,00" size="30" maxlength="4000">

  • 1

    It was exactly that, it works perfectly now. Thank you!

  • You’re welcome @Kimhanneman

  • If necessary multiply by a variable value of the field "unit value" #P1103_VALOR_UNITARIO, as it would be?

  • @Kimhanneman with this sample of code/ image do not know where this value is. By the code you placed the solution goes through this

Browser other questions tagged

You are not signed in. Login or sign up in order to post.