Jake Vanderwerf
3 days ago ba1e1ccf869b818f7a7a897264dfea05563a7796
assets/js/concise/TaxonomyCreator.js
@@ -55,7 +55,6 @@
      if (this.ui.form) {
         this.ui.form.addEventListener('change', (e) => {
            console.log('Creator form change, prevents default');
            e.preventDefault();
            e.stopPropagation();
         });
@@ -83,21 +82,22 @@
      if (!data.name || data.name.length < 2) return false;
      try {
         const response = await this.createTerm(data);
         let currentField = this.selector.currentField();
         if (!response.success) {
            // Term already exists - still add it
            if (response.term && response.term.id) {
               this.selector.setMessage(true, `Using existing "${response.term.name}"`);
               this.selector.setMessage(currentField,true, `Using existing "${response.term.name}"`);
               return response.term;
            }
            // Other failure
            this.selector.setMessage(true, response.message || 'Creation failed', false);
            this.selector.setMessage(currentField,true, response.message || 'Creation failed', false);
            return false;
         }
         if (response.term?.pending) {
            // Term requires approval
            this.selector.setMessage(
               currentField,
               true,
               `"${data.name}" submitted for approval`,
               false
@@ -120,12 +120,32 @@
    * Handle successful term creation
    */
   async handleSuccessfulCreation(term, data) {
      // Close create form
      this.ui.details.open = false;
      // Add term to store immediately - don't wait for fetch
      const fullTerm = {
         id: term.id,
         name: term.name,
         path: term.path || term.name,
         slug: term.slug || term.name.toLowerCase().replace(/\s+/g, '-'),
         parent: data.parent || 0,
         taxonomy: data.taxonomy,
         count: 0,
         hasChildren: false
      };
      // Clear cache to ensure fresh data
      // Add to store data immediately so addSelected can find it
      this.selector.store.data.set(term.id, fullTerm);
      // Close create form
      if (this.ui.details) {
         this.ui.details.open = false;
      }
      // Clear cache and refetch in background for accuracy
      this.selector.store.clearCache();
      await this.selector.store.fetch();
      // Don't await - let it happen async
      this.selector.store.fetch().catch(err => {
         console.warn('Background fetch after term creation failed:', err);
      });
   }
   /**