Use comma input with Bootstrap Touchspin

Asked

Viewed 139 times

1

I’m using Bootstrap Toutchspin to mount an input,

<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>

 <div class="form-group">
   <input type="text" id="P8473_QTDE" name="p_t05" value="0" size="25" onkeypress="return submitEnter(this,event)" class="mt10 form-control">
 </div>

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

<script>
$("input[name='p_t05']").TouchSpin({
  min: 0,
  max: 1000,
  boostat: 5,
  decimals: 3,
  forcestepdivisibility: "none",
  step: 1,
  maxboostedstep: 10,
  buttondown_class: "btn btn-ciano btn-lg btn-mob",
  buttonup_class: "btn btn-ciano btn-lg btn-mob",
  mousewheel: "true",
  initval: 0
});
</script>

So far wonder, but I need the input to use comma instead of dot.

  • In place of the point?

  • that’s right, sorry.

1 answer

1


If you want to exchange the point for the comma, you can replace the value input. Just use the events change touchspin.on.min touchspin.on.stopspin and replace one with the other:

$("input[name='p_t05']").TouchSpin({
  min: 0,
  max: 1000,
  boostat: 5,
  decimals: 3,
  forcestepdivisibility: "none",
  step: 1,
  maxboostedstep: 10,
  buttondown_class: "btn btn-ciano btn-lg btn-mob",
  buttonup_class: "btn btn-ciano btn-lg btn-mob",
  mousewheel: "true",
  initval: 0
}).on("change touchspin.on.min touchspin.on.stopspin", function(){
   var t = this;
   t.value = t.value.replace(/\./g, ",");
}).trigger("change");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.js"></script>
<div class="form-group">
   <input type="text" id="P8473_QTDE" name="p_t05" value="0" size="25" onkeypress="return submitEnter(this,event)" class="mt10 form-control">
</div>

  • Thank you very much!! worked.

  • When you change the value after the comma, the field loses the reference.

  • How so?....

  • by reporting 1,250 for example, and exiting the input the field loses the fraction reference and is being rounded to 1.

  • I get it. It’s just you go back to the point when you’re going to treat the number in the calculation. Only change the signals in the replace

  • When it comes time to treat the value as a number, you’ll do so: parseFloat($("input[name='p_t05']").val().replace(",", "."))

Show 1 more comment

Browser other questions tagged

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