From d38d825e3484d822ea3c1f0fb1df37ecf386b18a Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 04 Jan 2026 19:54:16 +0000
Subject: [PATCH] =TaxonomyCreator.js debugging

---
 assets/js/concise/TaxonomyCreator.js |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/assets/js/concise/TaxonomyCreator.js b/assets/js/concise/TaxonomyCreator.js
index 277185c..3c5f24d 100644
--- a/assets/js/concise/TaxonomyCreator.js
+++ b/assets/js/concise/TaxonomyCreator.js
@@ -135,6 +135,8 @@
 				const termPath = term.path || term.name;
 
 				field.selectedTerms.add(parseInt(term.id));
+
+				// Add to store's data map
 				this.selector.store.data.set(term.id, {
 					id: term.id,
 					name: term.name,
@@ -145,6 +147,7 @@
 					hasChildren: false,
 					slug: term.slug || termName.toLowerCase().replace(/\s+/g, '-')
 				});
+
 				this.selector.addTermToDisplay(field.id, term.id, term.name, termPath);
 
 				field.input.value = Array.from(field.selectedTerms).join(',');
@@ -153,8 +156,10 @@
 				field.autocompleteDropdown.hidden = true;
 				if (input) input.value = '';
 
-				// Only clear cache, don't refetch - term is already in store.data
-				this.selector.store.clearCache();
+				// Clear ALL cache for this taxonomy
+				// This forces next search to hit the server
+				await this.selector.store.clearCache();
+
 			} else if (response.reason === 'exists' && response.term) {
 				const term = response.term;
 				field.selectedTerms.add(parseInt(term.id));
@@ -240,7 +245,18 @@
 
 	async createTerm(name, parent = 0, taxonomy) {
 		try {
-			// Check existing data first without fetching
+			// Search to ensure we have latest data for duplicate check
+			await this.selector.store.setFilters({
+				taxonomy: taxonomy,
+				search: name,
+				page: 1,
+				parent: 0
+			});
+
+			// Wait a bit for the data to load
+			await new Promise(resolve => setTimeout(resolve, 100));
+
+			// Check if exact match exists in results
 			const exactMatch = Array.from(this.selector.store.data.values())
 				.find(term =>
 					term.taxonomy === taxonomy &&
@@ -248,6 +264,7 @@
 				);
 
 			if (exactMatch) {
+				// For modal context, show suggestions
 				if (this.createNew) {
 					this.showTermSuggestions([exactMatch], true);
 				}

--
Gitblit v1.10.0