mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
extending input validator functionality
This commit is contained in:
parent
51066a1962
commit
d491c96574
1 changed files with 13 additions and 0 deletions
13
main.js
13
main.js
|
@ -104,6 +104,8 @@ $(document).ready(function() {
|
|||
$("#content").on('keydown', 'input[type="number"]', function(e) {
|
||||
// whitelist all that we need for numeric control
|
||||
if ((e.keyCode >= 96 && e.keyCode <= 105) || (e.keyCode >= 48 && e.keyCode <= 57)) { // allow numpad and standard number keypad
|
||||
} else if(e.keyCode == 109 || e.keyCode == 189) { // minus on numpad and in standard keyboard
|
||||
} else if (e.keyCode == 8 || e.keyCode == 46) { // backspace and delete
|
||||
} else if (e.keyCode == 190 || e.keyCode == 110) { // allow and decimal point
|
||||
} else if ((e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13) { // allow arrows, enter
|
||||
} else {
|
||||
|
@ -140,6 +142,17 @@ $(document).ready(function() {
|
|||
element.val(element.data('previousValue'));
|
||||
}
|
||||
}
|
||||
|
||||
// if step is set and is float and value is int, convert to float, keep decimal places in float according to step *experimental*
|
||||
if (!isNaN(step) && step % 1 !== 0) {
|
||||
var decimal_places = String(step).split('.')[1].length;
|
||||
|
||||
if (val % 1 === 0) {
|
||||
element.val(val.toFixed(decimal_places));
|
||||
} else if (String(val).split('.')[1].length != decimal_places) {
|
||||
element.val(val.toFixed(decimal_places));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue