Bootstrap Touchspin Destroy Test
Testing ver. 4.2.5 (Apr 27 2018) Based on the plugin author's comment @ https://github.com/istvan-ujjmeszaros/bootstrap-touchspin/issues/70#issuecomment-381324785
by Sree K
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.js"></script>
<div class="form-group">
<input id="my-touchspin1" class="form-control" type="text" />
</div>
<button id="init-touchspin" class="btn btn-primary">
Init
</button>
<button id="destroy-touchspin" class="btn btn-danger"disabled>
Destroy
</button>
JavaScript
/* Bind click event on init btn */
$('#init-touchspin').on('click', function(e) {
e.preventDefault(); // optional here
// init touchspin with some basic conf options
$("#my-touchspin1").TouchSpin({
min: 0,
step: 0.001,
decimals: 3,
boostat: 5,
maxboostedstep: 10,
postfix: 'Mtrs.'
});
$('#destroy-touchspin').prop('disabled', false); // enable destroy btn
$(this).prop('disabled', true); // disable init btn
});
/* Bind click event on destroy btn */
$('#destroy-touchspin').on('click', function(e) {
e.preventDefault(); // optional here
$("#my-touchspin1").trigger('touchspin.destroy'); // destroy touchspin
$(this).prop('disabled', true); // disable destroy btn
$('#init-touchspin').prop('disabled', false); // enable init btn
});