Fix storage location deletion bug with special characters

- Created getLocationId() helper function to normalize location names to IDs
- Function removes special characters (apostrophes, etc.) before converting to ID
- Both rendering and action handlers now use same ID generation logic
- Fixes issue where locations with apostrophes couldn't be deleted
- Example: "Dottore's Study" now properly generates ID "Dottores-Study"
- Commented out debug logging
This commit is contained in:
Spicy_Marinara
2025-10-19 20:47:12 +02:00
parent dcbc788aa2
commit 6d105482c3
3 changed files with 49 additions and 20 deletions
+12 -1
View File
@@ -10,6 +10,17 @@ import { parseItems } from '../../utils/itemParser.js';
// Type imports
/** @typedef {import('../../types/inventory.js').InventoryV2} InventoryV2 */
/**
* Converts a location name to a safe ID for use in HTML element IDs.
* Must match the logic used in inventoryActions.js.
* @param {string} locationName - The location name
* @returns {string} Safe ID string
*/
export function getLocationId(locationName) {
// Remove all non-alphanumeric characters except spaces, then replace spaces with hyphens
return locationName.replace(/[^a-zA-Z0-9\s]/g, '').replace(/\s+/g, '-');
}
/**
* Renders the inventory sub-tab navigation (On Person, Stored, Assets)
* @param {string} activeTab - Currently active sub-tab ('onPerson', 'stored', 'assets')
@@ -160,7 +171,7 @@ export function renderStoredView(stored, collapsedLocations = [], viewMode = 'li
const itemString = stored[location];
const items = parseItems(itemString);
const isCollapsed = collapsedLocations.includes(location);
const locationId = escapeHtml(location).replace(/\s+/g, '-');
const locationId = getLocationId(location);
let itemsHtml = '';
if (items.length === 0) {