validation on header form

This commit is contained in:
Magnus Persson 2022-02-03 21:48:11 +01:00
parent 77cdbf7649
commit 838d062eea
3 changed files with 18 additions and 7 deletions

View File

@ -402,14 +402,14 @@
</div>
<div class="modal-body">
<label for="http-header" class="col-form-label">Header 1 (Header: value)</label>
<input type="text" maxlength="100" class="form-control" id="header1">
<input type="text" maxlength="100" class="form-control" id="header1" oninput="checkHeader(this)">
<label for="http-header" class="col-form-label">Header 2 (Header: value)</label>
<input type="text" maxlength="100" class="form-control" id="header2">
<input type="text" maxlength="100" class="form-control" id="header2" oninput="checkHeader(this)">
<input type="text" id="field1" hidden>
<input type="text" id="field2" hidden>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="btn-close" data-dismiss="modal">Close</button>
</div>
</div>
</div>
@ -433,6 +433,16 @@ $('#modal-http').on('hide.bs.modal', function (event) {
$(field1).val(modal.find('.modal-body #header1').val())
$(field2).val(modal.find('.modal-body #header2').val())
})
function checkHeader(input) {
console.log( input.value );
if (input.value != "" && input.value.indexOf(":") == -1) {
$("#btn-close").prop("disabled", true);
$(input).removeClass("is-valid").addClass("is-invalid");
} else {
$("#btn-close").prop("disabled", false);
$(input).removeClass("is-invalid").addClass("is-valid");
}
}
</script>
<script type="text/javascript">
@ -471,14 +481,15 @@ $('#modal-http').on('hide.bs.modal', function (event) {
// DS18B20 consumes 1mA
// For this estimation we use an average of 160mA
var pwr = 160; // mA
var pwrActive = 160; // mA per hour
var pwrSleep = 5; // mA per day
var batt = 2200; // mA
var rt = parseInt($("#runtime-average").val());
if(rt<1) rt = 2;
// The deep sleep will consume approx 1mA per day.
var powerPerDay = (24*3600)/(interval+rt)*(rt/3600)*pwr + 1;
var powerPerDay = (24*3600)/(interval+rt)*(rt/3600)*pwrActive + pwrSleep;
return batt/powerPerDay;
}

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@
"angle": 89.86,
"gravity": 1.1052,
"gravity-tempcorr": 1.1031,
"temp-c": 0,
"temp-c": 12,
"temp-f": 32,
"battery": 3.81,
"temp-format": "C",