Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic UI Numeric Up Down control

Is there any Semantic UI Numeric Up Down control with minimum, maximum and step count options ?

like image 792
Coder Avatar asked Oct 19 '25 10:10

Coder


2 Answers

We can use type as 'number' to get the required increment/decrement control.

<Input type="number"  />
like image 116
RajaSekhar K Avatar answered Oct 22 '25 06:10

RajaSekhar K


Not found such control so I made this code:

HTML

<div class="ui right labeled input">
    <input type="text" id="txtNum" value="5">
    <div class="ui mini vertical buttons">
        <button class="ui icon button" command="Up"> <i class="up chevron icon"></i>

        </button>
        <button class="ui icon button" command="Down"> <i class="down chevron icon"></i>

        </button>
    </div>
</div>

JS

// Constants
var KEY_UP = 38,
    KEY_DOWN = 40;

// Variables
var min = 0,
    max = 30,
    step = 1;

$('.ui.icon.button').click(function () {
    var command = $(this).attr('command');
    HandleUpDown(command);
});

$('#txtNum').keypress(function (e) {
    var code = e.keyCode;
    if (code != KEY_UP && code != KEY_DOWN) return;
    var command = code == KEY_UP ? 'Up' : code == KEY_DOWN ? 'Down' : '';
    HandleUpDown(command);
});

function HandleUpDown(command) {
    var val = $('#txtNum').val().trim();
    var num = val !== '' ? parseInt(val) : 0;

    switch (command) {
        case 'Up':
            if (num < max) num += step;
            break;
        case 'Down':
            if (num > min) num -= step;
            break;
    }

    $('#txtNum').val(num);
}

Here is the DEMO.

like image 40
Coder Avatar answered Oct 22 '25 08:10

Coder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!