Skip to content

Conversation

@arifulhoque7
Copy link
Contributor

@arifulhoque7 arifulhoque7 commented Jul 28, 2025

close issue

✨ Enhanced Tag Input with AJAX Autocomplete for Taxonomies

Improved the user experience for taxonomy fields marked as ajax-type by replacing dropdowns with a searchable text input using jQuery's suggest/autocomplete functionality. This is particularly useful for taxonomies with a large number of terms, such as product tags.

🔧 Key Improvements:

  • Replaced <select> dropdowns with <input type="text"> for ajax-enabled taxonomy fields in the form builder.
  • Implemented tax_input in PHP backend to properly handle submitted taxonomy terms.
  • Added secure nonce validation to the AJAX endpoint responsible for tag suggestions.
  • Users can now search and select tags dynamically with autocomplete support, reducing UI clutter and improving usability.

This enhancement makes managing large taxonomies more efficient and user-friendly.

Summary by CodeRabbit

  • New Features

    • Enhanced form field selection to better synchronize displayed options with underlying data.
    • Taxonomy fields with 'ajax' type now display a text input for searching, replacing the previous dropdown.
  • Bug Fixes

    • Improved initialization and updating of selected options to ensure consistent display as form data changes.
  • Security

    • Added a security nonce to AJAX search URLs for taxonomy fields.

@arifulhoque7 arifulhoque7 self-assigned this Jul 28, 2025
@arifulhoque7 arifulhoque7 added the needs: dev review This PR needs review by a developer label Jul 28, 2025
@arifulhoque7 arifulhoque7 requested a review from sapayth July 28, 2025 06:17
@coderabbitai
Copy link

coderabbitai bot commented Jul 28, 2025

Walkthrough

This change updates the taxonomy form field to use a text input for 'ajax' field types instead of a dropdown, both in the JavaScript templates and PHP renderer. Vue components for field selection and taxonomy were enhanced with new lifecycle hooks, watchers, and computed properties to better synchronize UI state with underlying data.

Changes

Cohort / File(s) Change Summary
Field Select Vue Enhancements
admin/form-builder/assets/js/components/field-select/index.js, assets/js/wpuf-form-builder-components.js
Improved initialization and synchronization of the selectedOption property in the field-select Vue component. Added a mounted hook, deep watchers on relevant props, and a new initializeSelectedOption method to ensure the selected option accurately reflects the current value and available options. Updates are deferred to the next Vue tick for consistency.
Form Taxonomy Vue Enhancements
admin/form-builder/assets/js/components/form-taxonomy/index.js, assets/js/wpuf-form-builder-components.js
Added two computed properties to the form-taxonomy Vue component: should_show_text_input (true for 'ajax' field type) and should_show_ajax_dropdown (always false), ensuring the UI presents a text input instead of a dropdown for ajax-based taxonomy fields.
Taxonomy Field Template Update
assets/js-templates/form-components.php
Changed the taxonomy form field template to render a text input instead of a dropdown when the field type is 'ajax'. The input includes appropriate placeholder text and disables autocomplete.
PHP Taxonomy Field Rendering
includes/Fields/Form_Field_Post_Taxonomy.php
Modified the render method to use a text input for 'ajax' field types by always calling tax_input with a null post ID. Updated the AJAX search URL in tax_input to include a nonce parameter for security.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Suggested labels

QA Approved, Ready to Merge

Suggested reviewers

  • sapayth

Poem

A bunny hopped through fields of code,
Swapping dropdowns for inputs on the road.
With Vue’s keen watch and PHP’s care,
AJAX searches now float through the air.
Placeholders whisper, nonces keep guard—
This review’s a hop, not at all hard! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b56e6a6 and a5342d5.

📒 Files selected for processing (5)
  • admin/form-builder/assets/js/components/field-select/index.js (1 hunks)
  • admin/form-builder/assets/js/components/form-taxonomy/index.js (1 hunks)
  • assets/js-templates/form-components.php (1 hunks)
  • assets/js/wpuf-form-builder-components.js (2 hunks)
  • includes/Fields/Form_Field_Post_Taxonomy.php (2 hunks)
🔇 Additional comments (9)
includes/Fields/Form_Field_Post_Taxonomy.php (2)

425-426: Excellent security enhancement with nonce validation.

Adding nonce validation to the AJAX search URL is a crucial security improvement that prevents CSRF attacks on the tag search endpoint. The implementation correctly uses WordPress's built-in nonce system.


100-102: Nullifying $post_id won’t prevent existing terms from loading

The render method populates $this->terms via wp_get_post_terms( $post_id, … ) before the switch, and tax_input() uses $this->terms to set the input’s value. The $post_id parameter passed into tax_input() is never used for loading terms, so setting it to null does not impact editing existing posts. All current term values will still appear as expected.

admin/form-builder/assets/js/components/form-taxonomy/index.js (1)

30-38: Clean implementation of conditional UI logic.

The computed properties provide clear, declarative logic for controlling when to show the text input vs dropdown for taxonomy fields. The explicit should_show_ajax_dropdown: false ensures the old dropdown UI is completely disabled for ajax fields.

assets/js-templates/form-components.php (1)

1424-1432: Well-implemented template change for AJAX taxonomy fields.

The new text input element properly replaces the dropdown for 'ajax' type taxonomy fields. Good attention to UX details like the dynamic placeholder fallback and autocomplete="off" to prevent interference with AJAX search functionality.

admin/form-builder/assets/js/components/field-select/index.js (3)

15-18: Good addition of mounted lifecycle hook.

Properly initializes the selectedOption when the component mounts, ensuring the UI state matches the field data from the start.


20-43: Comprehensive watchers for maintaining UI synchronization.

The watchers cover all necessary scenarios for keeping the selectedOption in sync with the underlying data. Good use of deep watching for objects and immediate: true for initialization.


45-66: Well-structured initialization method with proper safeguards.

The method handles all edge cases appropriately with proper null checks and uses $nextTick to ensure reactive state consistency. The logic for handling current values, defaults, and fallbacks is sound.

assets/js/wpuf-form-builder-components.js (2)

831-882: LGTM - Well-implemented option synchronization.

The addition of lifecycle hooks and watchers to keep the selectedOption display synchronized with the underlying data model is well-implemented. The fallback logic (current value → default → placeholder) handles various initialization scenarios appropriately, and the use of $nextTick ensures proper DOM update timing.


2029-2037: Excellent implementation aligning with PR objectives.

These computed properties effectively implement the core functionality described in the PR objectives - replacing traditional dropdown menus with searchable text inputs for ajax-type taxonomy fields. The logic is clean and will improve UX for taxonomies with many terms like product tags.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sapayth sapayth added Dev Review Done and removed needs: dev review This PR needs review by a developer labels Jul 30, 2025
@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added QA Approved This PR is approved by the QA team and removed needs: testing labels Jul 30, 2025
@sapayth sapayth merged commit 30c140f into weDevsOfficial:develop Jul 31, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dev Review Done QA Approved This PR is approved by the QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tag Auto-Suggestion Not Available in Product Forms (Pro Version)

3 participants