| | |
| | | field.autocompleteDropdown.hidden = true; |
| | | if (input) input.value = ''; |
| | | |
| | | // Only clear cache, don't refetch - term is already in store.data |
| | | // Clear cache AND refresh this taxonomy's data |
| | | this.selector.store.clearCache(); |
| | | |
| | | // Trigger a background refresh for this taxonomy |
| | | await this.selector.store.setFilters({ |
| | | taxonomy: field.taxonomy, |
| | | page: 1, |
| | | search: '', |
| | | parent: 0 |
| | | }); |
| | | } else if (response.reason === 'exists' && response.term) { |
| | | const term = response.term; |
| | | field.selectedTerms.add(parseInt(term.id)); |
| | |
| | | |
| | | 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 && |
| | |
| | | ); |
| | | |
| | | if (exactMatch) { |
| | | // For modal context, show suggestions |
| | | if (this.createNew) { |
| | | this.showTermSuggestions([exactMatch], true); |
| | | } |