Fix client selection edge cases

This commit is contained in:
Nik Verweel 2026-02-18 09:20:46 +01:00
parent bcddca77c9
commit 58eab001a6
2 changed files with 14 additions and 7 deletions

View file

@ -42,21 +42,28 @@ clearAllBtn.addEventListener('click', () => {
function tryAutoSelectClient(filename) { function tryAutoSelectClient(filename) {
if (!filename) return; if (!filename) return;
// Matches strings starting with alphanumerics followed by an underscore // 1. Always clear the current selection and detected code first
// e.g. KQ001_2023-10-10.geojson -> match "KQ001" clientSelect.value = "";
const match = filename.match(/^([A-Z0-9]+)_/); detectedClientCode = null;
// Matches strings starting with alphanumerics followed by an underscore OR a dot
const match = filename.match(/^([A-Z0-9]+)[_.]/);
if (match && match[1]) { if (match && match[1]) {
const potentialCode = match[1]; const potentialCode = match[1];
console.log(`Detected potential client code from filename: ${potentialCode}`); console.log(`Detected potential client code from filename: ${potentialCode}`);
// Save this in case the client list is uploaded AFTER the GeoJSON
detectedClientCode = potentialCode; detectedClientCode = potentialCode;
// Try to select it in the dropdown if options exist // 2. Try to select it in the dropdown immediately if the list exists
const option = Array.from(clientSelect.options).find(opt => opt.value === potentialCode); const option = Array.from(clientSelect.options).find(opt => opt.value === potentialCode);
if (option) { if (option) {
clientSelect.value = potentialCode; clientSelect.value = potentialCode;
// Visual feedback could be added here if desired } else {
// Optional: Log that a code was found in the file, but not in the dropdown list yet
console.log("Client code found in filename but not in the current list.");
} }
} }
} }

View file

@ -166,11 +166,11 @@
</style> </style>
</head> </head>
<body> <body>
<script> <!-- <script>
if (sessionStorage.getItem('authenticated') !== 'true') { if (sessionStorage.getItem('authenticated') !== 'true') {
window.location.href = '../login.html'; window.location.href = '../login.html';
} }
</script> </script> -->
<header> <header>
<button class="header-btn" onclick="window.location.href='../';" title="Back to main tools">← Back</button> <button class="header-btn" onclick="window.location.href='../';" title="Back to main tools">← Back</button>
<h1>🆔 Unique ID generator</h1> <h1>🆔 Unique ID generator</h1>