Current time display in qso log form

This commit is contained in:
Sebastian Lohff 2017-01-23 00:00:57 +01:00
parent 3dd9930d0f
commit 1fa184eb98
2 changed files with 26 additions and 1 deletions

View File

@ -40,6 +40,7 @@ def log(request):
if request.method == 'POST':
form = QSOForm(user=request.user, data=request.POST)
form.helper.form_tag = False
if form.is_valid():
l = form.instance
if not l.time:
@ -63,6 +64,7 @@ def log(request):
data["band"] = qsos[0].band
form = QSOForm(request.user, initial=data)
form.helper.form_tag = False
return render(request, 'contest/log.html', {'form': form, 'qsos': qsos})

View File

@ -28,7 +28,15 @@
</style>
<form method="post" id="qso-log-form" class="form-inline" action="{% url "contest:log" %}">
<div class="form-group">
<label class="control-label">Time</label>
<div class="controls">
<p id="id_curr_time" class="form-control-static">noot</p>
</div>
</div>
{% crispy form %}
</form>
</div>
</div>
@ -130,6 +138,21 @@ $(document).ready(function() {
$("#id_otherNo").on("keydown", function(e) { return mvFocusOnSpace(e, "#id_refStr"); });
$("#id_refStr").on("keydown", function(e) { return mvFocusOnSpace(e, "#submit-id-submit"); });
// display current time in log form
function zeropad(n) {
// srsly, how can javascript not have a printf/zeropad function?
if(n < 10)
return "0" + n;
else
return "" + n;
}
function displayTimeInForm() {
var d = new Date();
dstr = zeropad(d.getHours()) + ":" + zeropad(d.getMinutes()) + ":" + zeropad(d.getSeconds());
$("#id_curr_time").text(dstr);
}
window.setInterval(displayTimeInForm, 200);
});
</script>