bootstrap-input-spinner

A Bootstrap 4 / jQuery plugin to create input spinner elements for number input.

Source code and documentation

GitHub repository

Examples

Simple Integer

<input type="number" value="500" min="0" max="1000" step="10"/>

Floating Point

<input type="number" value="4.5" data-decimals="2" min="0" max="9" step="0.1"/>

Handle `change` and `input` events

Value:

var $changedInput = $("#changedInput")
var $output = $("#valueOutput")
$changedInput.on("change", function (event) {
    $output.html($changedInput.val())
})

Programmatic change of value

Net

Gross (+19%)

$inputNet.on("change", function (event) {
    $inputGross.val($inputNet.val() * 1.19)
})
$inputGross.on("change", function (event) {
    $inputNet.val($inputGross.val() / 1.19)
})

Classes 'is-invalid' and 'is-valid'; properties 'required' and 'placeholder'

To enable server-side validation, the classes 'is-invalid' and 'is-valid' of the original input are copied to the created input element. Also 'required' and 'placeholder' are copied.

<input placeholder="Enter a number" required type="number" value="" min="-100" max="100"/>

Script

This script enables the InputSpinner for all inputs with type='number' on this page. No extra css needed, just Bootstrap 4.

<script>
    $("input[type='number']").InputSpinner()
</script>

Sizing

You can set the group css class via configuration.

Small

$("input.small").InputSpinner({groupClass: "input-group-sm"})

Large

$("input.large").InputSpinner({groupClass: "input-group-lg"})