From 70885912605c48412054960d0b08c412ab134c86 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Mon, 15 Apr 2024 21:44:55 +0200 Subject: [PATCH] Short name autofill --- .../main/webapp/js/tour-information.inc.js | 25 +++++++++++++++++++ .../main/webapp/js/tour-registration.inc.js | 1 + 2 files changed, 26 insertions(+) diff --git a/view-webapp/src/main/webapp/js/tour-information.inc.js b/view-webapp/src/main/webapp/js/tour-information.inc.js index 4250f63..7196b5e 100644 --- a/view-webapp/src/main/webapp/js/tour-information.inc.js +++ b/view-webapp/src/main/webapp/js/tour-information.inc.js @@ -1,3 +1,12 @@ +let manualShortName; + +function autofillShortName(dt, loc) { + if (!manualShortName && dt !== '' && loc !== '') { + let ymd = parseDate(dt).replaceAll(/-/g, ''); + $('input[name="shortName"]')[0].value = `${ymd}-${loc}`; + } +} + onLoad(() => { $('#edit').on('click', e => { e.preventDefault(); @@ -253,4 +262,20 @@ onLoad(() => { } }); }); + let shortName = $('input[name="shortName"]'); + manualShortName = (shortName[0].value !== ''); + let startDate = $('input[name="startDate"]'); + let location = $('input[name="location"]'); + startDate.on('change', e => { + if (!manualShortName) autofillShortName(startDate[0].value, location[0].value) + }); + $('#date-range').on('changeDate', e => { + if (!manualShortName) autofillShortName(startDate[0].value, location[0].value) + }); + location.on('input', e => { + if (!manualShortName) autofillShortName(startDate[0].value, location[0].value) + }); + shortName.on('input', e => { + manualShortName = true; + }); }); diff --git a/view-webapp/src/main/webapp/js/tour-registration.inc.js b/view-webapp/src/main/webapp/js/tour-registration.inc.js index 7978350..2a8c14e 100644 --- a/view-webapp/src/main/webapp/js/tour-registration.inc.js +++ b/view-webapp/src/main/webapp/js/tour-registration.inc.js @@ -1,4 +1,5 @@ const SEARCH_DELAY = 100; +const SEARCH_DELAY = 100; let searchTimer = undefined; let resultTemplate; let searchResult;