mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-14 03:49:53 +03:00
Couple of improvements
- better handling of negative numbers - improved regex pattern - limits to min and max values
This commit is contained in:
parent
43b69d434a
commit
30317ede79
2 changed files with 24 additions and 7 deletions
|
@ -522,7 +522,7 @@ var Settings = (function () {
|
||||||
}
|
}
|
||||||
element.attr('step', step.toFixed(decimalPlaces));
|
element.attr('step', step.toFixed(decimalPlaces));
|
||||||
|
|
||||||
if ((multiplier !== 'FAHREN' || multiplier !== 'TZHOURS') && multiplier !== 1) {
|
if (multiplier !== 'FAHREN' && multiplier !== 'TZHOURS' && multiplier !== 1) {
|
||||||
element.attr('min', (parseFloat(element.attr('min')) / multiplier).toFixed(decimalPlaces));
|
element.attr('min', (parseFloat(element.attr('min')) / multiplier).toFixed(decimalPlaces));
|
||||||
element.attr('max', (parseFloat(element.attr('max')) / multiplier).toFixed(decimalPlaces));
|
element.attr('max', (parseFloat(element.attr('max')) / multiplier).toFixed(decimalPlaces));
|
||||||
}
|
}
|
||||||
|
@ -535,13 +535,12 @@ var Settings = (function () {
|
||||||
element.attr('max', toFahrenheit(element.attr('max')).toFixed(decimalPlaces));
|
element.attr('max', toFahrenheit(element.attr('max')).toFixed(decimalPlaces));
|
||||||
newValue = toFahrenheit(oldValue).toFixed(decimalPlaces);
|
newValue = toFahrenheit(oldValue).toFixed(decimalPlaces);
|
||||||
} else if (multiplier === 'TZHOURS') {
|
} else if (multiplier === 'TZHOURS') {
|
||||||
element.removeAttr('min');
|
|
||||||
element.removeAttr('max');
|
|
||||||
element.attr('type', 'text');
|
element.attr('type', 'text');
|
||||||
element.attr('pattern', '[0-9]{2}:[0-9]{2}');
|
element.removeAttr('step');
|
||||||
|
element.attr('pattern', '([0-9]{2}|[-,0-9]{3}):([0-9]{2})');
|
||||||
let hours = Math.floor(oldValue/60);
|
let hours = Math.floor(oldValue/60);
|
||||||
let mins = oldValue - (hours*60);
|
let mins = oldValue - (hours*60);
|
||||||
newValue = padZeros(hours, 2) + ':' + padZeros(mins, 2);
|
newValue = ((hours < 0) ? padZeros(hours, 3) : padZeros(hours, 2)) + ':' + padZeros(mins, 2);
|
||||||
} else {
|
} else {
|
||||||
newValue = Number((oldValue / multiplier)).toFixed(decimalPlaces);
|
newValue = Number((oldValue / multiplier)).toFixed(decimalPlaces);
|
||||||
}
|
}
|
||||||
|
@ -581,6 +580,14 @@ var Settings = (function () {
|
||||||
} else if (multiplier === 'TZHOURS') {
|
} else if (multiplier === 'TZHOURS') {
|
||||||
let inputTZ = input.val().split(':');
|
let inputTZ = input.val().split(':');
|
||||||
value = (parseInt(inputTZ[0]) * 60) + parseInt(inputTZ[1]);
|
value = (parseInt(inputTZ[0]) * 60) + parseInt(inputTZ[1]);
|
||||||
|
|
||||||
|
if (value > parseInt(input.attr('max'))) {
|
||||||
|
value = parseInt(input.attr('max'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value < parseInt(input.attr('min'))) {
|
||||||
|
value = parseInt(input.attr('min'));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
multiplier = parseFloat(multiplier);
|
multiplier = parseFloat(multiplier);
|
||||||
|
|
||||||
|
|
14
main.js
14
main.js
|
@ -651,8 +651,18 @@ String.prototype.format = function () {
|
||||||
|
|
||||||
function padZeros(val, length) {
|
function padZeros(val, length) {
|
||||||
let str = val.toString();
|
let str = val.toString();
|
||||||
return str.length < length ? padZeros("0" + str, length) : str;
|
|
||||||
};
|
if (str.length < length) {
|
||||||
|
if (str.charAt(0) === '-') {
|
||||||
|
str = "-0" + str.substring(1);
|
||||||
|
str = padZeros(str, length);
|
||||||
|
} else {
|
||||||
|
str = padZeros("0" + str, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
function updateActivatedTab() {
|
function updateActivatedTab() {
|
||||||
var activeTab = $('#tabs > ul li.active');
|
var activeTab = $('#tabs > ul li.active');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue