fix: web: add form: pre-fill date again; focus description

This commit is contained in:
Simon Michael 2022-08-26 11:57:51 +01:00
parent d718f2c50c
commit 2f00211554

View File

@ -4,6 +4,9 @@
// STARTUP // STARTUP
$(document).ready(function() { $(document).ready(function() {
// add form helpers XXX move to addForm ?
// date picker // date picker
// http://bootstrap-datepicker.readthedocs.io/en/latest/options.html // http://bootstrap-datepicker.readthedocs.io/en/latest/options.html
var dateEl = $('#dateWrap').datepicker({ var dateEl = $('#dateWrap').datepicker({
@ -13,7 +16,7 @@ $(document).ready(function() {
weekStart: 1 // Monday weekStart: 1 // Monday
});; });;
// ensure add form always focuses its first field // focus and pre-fill the add form whenever it is shown
$('#addmodal') $('#addmodal')
.on('shown.bs.modal', function() { .on('shown.bs.modal', function() {
addformFocus(); addformFocus();
@ -163,9 +166,14 @@ function addformLastAmountBindKey() {
$('.amount-input:last').keypress(addformAddPosting); $('.amount-input:last').keypress(addformAddPosting);
} }
// Focus the first add form field. // Pre-fill today's date and focus the description field in the add form.
function addformFocus() { function addformFocus() {
focus($('#addform input#date')); $('#addform input[name=date]').val(isoDate());
focus($('#addform input[name=description]'));
}
function isoDate() {
return new Date().toLocaleDateString("sv"); // https://stackoverflow.com/a/58633651/84401
} }
// Focus a jquery-wrapped element, working around http://stackoverflow.com/a/7046837. // Focus a jquery-wrapped element, working around http://stackoverflow.com/a/7046837.