| | |
| | | |
| | | if (!field) return; |
| | | |
| | | |
| | | // Store current value immediately (fixes fast typing issue) |
| | | const query = e.target.value.trim(); |
| | | field.currentAutocompleteQuery = query; |
| | | |
| | | if (query.length < 2) { |
| | | if (field.autocompleteDropdown) { |
| | |
| | | } |
| | | |
| | | this.activeField = fieldId; |
| | | this.currentConfig = field; |
| | | |
| | | |
| | | if (field.canCreate && ! this.creator) { |
| | | this.creator = new window.jvbTaxCreator(this); |
| | | } |
| | | this.isAutocompleteActive = true; |
| | | |
| | | if (field.autocompleteDropdown) { |
| | |
| | | }); |
| | | } |
| | | |
| | | // Offer to create new term if creator is available |
| | | if (this.creator) { |
| | | const createOption = this.creator.createAutocompleteOption(query, field); |
| | | // Use stored current query instead of debounced one |
| | | const currentQuery = field.currentAutocompleteQuery || query; |
| | | if (field.canCreate && currentQuery && window.jvbTaxCreator) { |
| | | const createOption = this.createNewTermOption(currentQuery); |
| | | dropdown.appendChild(createOption); |
| | | } |
| | | |
| | | dropdown.hidden = false; |
| | | } |
| | | |
| | | createNewTermOption(query) { |
| | | const button = document.createElement('button'); |
| | | button.type = 'button'; |
| | | button.className = 'autocomplete-item create-term'; |
| | | button.dataset.query = query; |
| | | button.innerHTML = `<strong>Create:</strong> "${query}"`; |
| | | |
| | | return button; |
| | | } |
| | | |
| | | createAutocompleteTermElement(field, term) { |
| | | const item = document.createElement('button'); |
| | | item.type = 'button'; |