Skip to content

Allow standard Text fields to be used as Checkboxes, Radio, or List filters#95

Open
PixedBo wants to merge 2 commits intoJoomline:masterfrom
PixedBo:feature-text-checkboxes
Open

Allow standard Text fields to be used as Checkboxes, Radio, or List filters#95
PixedBo wants to merge 2 commits intoJoomline:masterfrom
PixedBo:feature-text-checkboxes

Conversation

@PixedBo
Copy link
Copy Markdown

@PixedBo PixedBo commented Mar 18, 2026

Motivation

Currently, the module only supports checkboxes, radio, and list layouts for custom fields that natively possess an options array. However, it is very common to have standard text fields containing a limited, repetitive set of values that would be perfectly suited for multiple-choice filtering.

What this PR does

This PR introduces the ability to render and filter standard text fields as multiple-choice inputs, specifically focusing on the com_content component. It automatically generates the options based on the actual data present in the database for articles.

Detailed Changes:

  1. Module (src/Helper/JlcontentfieldsfilterHelper.php):

    • Intercepts text fields when the selected layout is checkboxes, radio, or list.
    • Queries the #__fields_values table to extract DISTINCT values for that specific field.
    • Dynamically builds the options array so the existing layout files can render them properly.
    • Temporarily mimics the layout type to allow the native setHiddenOptions() function to hide empty options based on the com_content category context.
  2. System Plugin (src/Extension/Jlcontentfieldsfilter.php):

    • Updates the SQL query builder inside onAfterRoute() for the case 'text': block.
    • Detects if the input is a standard array of selected options (coming from the new checkboxes/list) and safely constructs an IN (...) clause.
    • Preserves the existing logic for range arrays (from/to) and standard single-string LIKE searches.

How to Test / Steps to Reproduce

1. Setup the Custom Field

  • In the Joomla Backend, go to Content > Fields.
  • Create a new Custom Field of type Text (e.g., named "City" or "Color").
  • In the "Filtering Params" tab, set the View in the filter to Text and Individual layout to checkboxes

2. Create Test Content

  • Go to Content > Articles and create 3 test articles within the same Category (e.g., "Test Category").
  • Assign values to the new Text field:
    • Article 1: "Rome"
    • Article 2: "Milan"
    • Article 3: "Rome"
    • (Optional) Article 4: Leave the field empty.

3. Configure the Module

  • Go to System > Site Modules and publish the MOD_JLCONTENTFIELDSFILTER module on a visible position.
  • Assign the module to the "Test Category".

4. Test the Frontend Rendering

  • Navigate to the "Test Category" page on the frontend.
  • Look at the filter module: it should now display a checkbox list with exactly two options: "Rome" and "Milan" (dynamically extracted via DISTINCT).
  • Empty values from Article 4 should not be rendered as an empty option.

5. Test the Filtering Logic

  • Check "Rome" and submit the filter form.
  • Verify that the category view updates to show only Article 1 and Article 3.
  • Reset the filter, check "Milan", submit, and verify that only Article 2 is displayed.

@PixedBo PixedBo marked this pull request as ready for review March 18, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant