Skip to content

Conversation

@GaryJones
Copy link
Collaborator

Summary

  • Adds Select2-based autocomplete for conditional arguments (categories, tags, pages, posts) in the Add New Ad Code form
  • Uses Select2 loaded from jsDelivr CDN (with graceful fallback if unavailable)
  • Implements AJAX search with 3-character minimum and 100 result limit as suggested in issue discussion
  • Hides arguments field for conditionals that don't take parameters (is_home, is_front_page, etc.)
  • Improves admin UI layout: Configuration section full-width, "Existing Ad Codes" heading, better field labels in Edit view
  • Extensible via acm_autocomplete_conditionals and acm_autocomplete_results filters

Note: Autocomplete is currently only enabled for the Add form. The inline Edit form retains text inputs - a dedicated edit page is planned as a follow-up improvement (see #198).

Test plan

  • Navigate to Ad Code Manager settings page
  • In "Add New Ad Code", select a conditional like is_category or is_tag
  • Verify the argument input becomes a Select2 autocomplete field
  • Type 3+ characters and verify suggestions appear via AJAX
  • Select a suggestion and verify it's applied
  • Verify custom values can still be typed if not in autocomplete results
  • Select is_home or is_front_page and verify arguments field is hidden
  • Verify "Add another condition" button only appears after first condition is selected
  • Run composer test:integration - all 28 tests should pass

Fixes #42

🤖 Generated with Claude Code

GaryJones and others added 7 commits December 21, 2025 14:30
Add Select2-based autocomplete for conditional arguments (categories,
tags, pages, posts) to make it easier for users to select values when
configuring ad code conditions.

Key implementation details:
- Uses WordPress's bundled SelectWoo/Select2 library
- AJAX search with 3-character minimum and 100 result limit
- Supports both taxonomy terms and post type searches
- Allows custom values via Select2's tags option
- Extensible via `acm_autocomplete_conditionals` and
  `acm_autocomplete_results` filters

Fixes #42

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Select2 with AJAX data requires hidden inputs, not text inputs.
Also fix test pollution by dequeuing scripts between tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Select2/selectWoo is not bundled with WordPress core - it comes from
WooCommerce. When neither selectWoo nor select2 is registered, we now
load Select2 v4.0.13 from jsDelivr CDN.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Select2 with AJAX requires a <select> element, not an input.
Dynamically create a select element when initializing autocomplete
and restore the original input when switching conditionals.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Conditionals like is_home, is_front_page, is_404, etc. don't accept
arguments, so showing an input field is confusing. Now the arguments
field is hidden when these conditionals are selected.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Change "Add more" to "Add another condition"
- Remove boxed styling from Configuration section
- Fix Select2 field heights to match native inputs
- Fix Edit labels to use proper labels from provider config
- Link labels to their corresponding form fields
- Hide "Add another condition" button until first condition selected
- Show Logical Operator only when 2+ conditions are set
- Move Logical Operator field near Conditionals in Edit view

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove inline edit autocomplete initialization (will be addressed
  with dedicated edit page in future PR)
- Scope all autocomplete functionality to #add-adcode form only
- Add isSelect2Available() check to gracefully handle CDN failures
- Prevent JS errors when Select2 fails to load

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@GaryJones GaryJones requested a review from a team as a code owner December 21, 2025 17:14
@GaryJones GaryJones self-assigned this Dec 21, 2025
@GaryJones GaryJones added the type: enhancement New feature or request label Dec 21, 2025
@GaryJones GaryJones added this to the 0.8.0 milestone Dec 21, 2025
@GaryJones GaryJones merged commit 9951b1e into develop Dec 21, 2025
17 checks passed
@GaryJones GaryJones deleted the feature/42-conditional-autocomplete branch December 21, 2025 22:17
@GaryJones GaryJones mentioned this pull request Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Autocomplete/dropdown or any other assisted input with generic conditionals

2 participants