From 474109a5df0a06f5343ab184838fe2d80e3872a8 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 11 Jan 2026 19:23:20 +0000
Subject: [PATCH] =Fixed timeline CRUD.js issue where this.activeItem was set null when we still needed it
---
inc/forms/TaxonomySelector.php | 92 ++++++++++++++++++++++++++++-----------------
1 files changed, 57 insertions(+), 35 deletions(-)
diff --git a/inc/forms/TaxonomySelector.php b/inc/forms/TaxonomySelector.php
index 29f7df3..eccabc2 100644
--- a/inc/forms/TaxonomySelector.php
+++ b/inc/forms/TaxonomySelector.php
@@ -32,9 +32,9 @@
$this->id = sanitize_key($id);
$this->taxonomy = jvbCheckBase($taxonomy);
$this->name = jvbNoBase($taxonomy);
+
$this->title = JVB_TAXONOMY[$this->name]['plural'];
$this->base = $config['base']??'';
-
$this->config = wp_parse_args($config, [
'types' => false, // for feed block implementation
'max' => 0, // 0 = unlimited
@@ -98,11 +98,8 @@
<h3 id="modal-title">Select Taxonomy</h3>
</header>
- <div class="selected-items-section">
- <div class="selected-items row" role="region" aria-label="Selected items">
- <!-- Selected items will be populated here -->
- </div>
- </div>
+
+ <div class="selected-items row" role="region" aria-label="Selected items"></div>
<div class="items-wrap">
<!-- Common/Favorite terms section -->
@@ -126,10 +123,10 @@
<!-- Terms will be populated here -->
</ul>
- <!-- Loading indicator -->
- <p class="loading" hidden aria-live="polite">
- <span>loading items</span>
+ <p class="message" hidden aria-live="polite">
+ { <span>loading items</span> }
</p>
+ <button class="submit-term" hidden data-ignore><strong>Create: </strong> "<span></span>"</button>
<!-- Infinite scroll sentinel -->
<div class="scroll-sentinel" aria-hidden="true"></div>
@@ -138,15 +135,15 @@
<!-- Search section -->
<div class="search-wrapper">
<div class="search-bar">
- <?= jvbSearch('Search terms') ?>
+ <?= jvbSearch('Search terms', 'search-terms') ?>
</div>
</div>
<!-- Create new term section -->
- <details class="create-new-term" hidden>
+ <details class="create-term" hidden>
<summary class="row btw">Add New Term</summary>
<div class="create-new-term-section">
- <form class="create-term-form" data-nocache data-form-id="create-term" data-save="terms">
+ <form class="create-term" data-nocache data-form-id="create-term" data-save="terms">
<div class="form-group">
<label for="term_name">Term Name:</label>
<input type="text" name="term_name" id="term_name" required>
@@ -158,14 +155,8 @@
<option value="0">None (Top Level)</option>
</select>
</div>
-
- <button type="button" class="submit-term">Add Term</button>
</form>
- <div class="loading-message create-term" hidden>
- <span id="typed-text"></span>
- <span class="cursor">|</span>
- </div>
</div>
</details>
<?= jvbModalActions(); ?>
@@ -174,12 +165,15 @@
<template class="loadingItems">
<p>{ <span>loading items</span> }</p>
</template>
- <template class="noResults">
+ <template class="autocompleteItem">
+ <li class="autocomplete item btn"></li>
+ </template>
+ <template class="noTermResults">
<p>{ <span>nothing found</span> }</p>
</template>
<template class="termListItem">
<li>
- <input type ="checkbox">
+ <input type="checkbox">
<label>
<span class="term-name"></span>
</label>
@@ -193,7 +187,7 @@
<template class="selectedTerm">
<div class="selected-item row">
<span class="item-name"></span>
- <button type="button" class="remove-item row"><?=jvbIcon('x')?></button>
+ <button type="button" class="remove-term row"><?=jvbIcon('x')?></button>
</div>
</template>
<template class="termBreadcrumb">
@@ -211,6 +205,10 @@
* @return string The rendered HTML
*/
public function render(array $selected = [], string $extra = ''): string {
+
+ if (array_key_exists('output', $this->config) && $this->config['output'] === 'minimal') {
+ return $this->renderTaxonomyToggle($selected, $extra);
+ }
// Build data attributes
$dataAttrs = $this->buildDataAttributes($selected);
@@ -237,28 +235,52 @@
<?= $hasAutocomplete ?>
title="Open <?= $this->singular ?> Selector"
aria-label="Select <?= esc_attr($this->plural) ?>">
- <?= jvbIcon('plus-square', ['title' => 'Add ' . $this->title]) ?>
+ <?= jvbIcon('plus-square') ?>
</button>
- <input type="text" id="<?= $this->base ?><?= esc_attr($this->config['name']) ?>-autocomplete" autocomplete="off" data-ignore data-autocomplete>
- <ul class="autocomplete-dropdown" hidden>
+ <?php if ($hasAutocomplete !== '') { ?>
+ <input type="text" id="<?= $this->base ?><?= esc_attr($this->config['name']) ?>-autocomplete" autocomplete="off" data-ignore data-autocomplete>
+ <div class="auto-wrapper" hidden>
+ <ul class="search-results">
+ </ul>
+ <p class="message" hidden aria-live="polite">
+ { <span>loading items</span> }
+ </p>
+ <button class="submit-term" hidden data-ignore><strong>Create: </strong> "<span></span>"</button>
+ </div>
- </ul>
+ <?php } ?>
</div>
-
- <div class="selected-items row" role="region" aria-label="Selected <?= esc_attr($this->plural) ?>">
- <?php if (!empty($selected)): ?>
- <?php foreach ($selected as $termId): ?>
- <?php $this->renderSelectedTerm($termId); ?>
- <?php endforeach; ?>
- <?php endif; ?>
- </div>
-
+ <?php
+ $selectedItems = '';
+ if (!empty($selected)):
+ ob_start();
+ foreach ($selected as $termId):
+ $this->renderSelectedTerm($termId);
+ endforeach;
+ $selectedItems = ob_get_clean();
+ endif;
+ ?>
+ <div class="selected-items row" role="region" aria-label="Selected <?= esc_attr($this->plural) ?>"><?=$selectedItems?></div>
<?= $extra ?>
</div>
<?php
return ob_get_clean();
}
+ protected function renderTaxonomyToggle(array $selected = [], string $extra = ''): string
+ {
+ return sprintf(
+ '<button type="button" data-icon="%s" data-filter="taxonomy" data-taxonomy="%s" data-type="selector" data-single="%s" data-plural="%s" title="Filter by %s">%s<span class="label">%s</span></button>',
+ JVB_TAXONOMY[$this->name]['icon'],
+ $this->name,
+ $this->singular,
+ $this->plural,
+ $this->singular,
+ jvbIcon($this->config['icon']),
+ $this->singular
+ );
+ }
+
/**
* Build data attributes string for the toggle button
*/
@@ -318,7 +340,7 @@
<div class="selected-item row" data-id="<?= esc_attr($termId) ?>">
<span><?= esc_html($termPath) ?></span>
<button type="button"
- class="remove-item row"
+ class="remove-term row"
aria-label="Remove <?= esc_attr($term->name) ?>">
<?= jvbIcon('x') ?>
</button>
--
Gitblit v1.10.0