JReviews logo
Guides My site
← All guides Community guide

Search numeric ranges with friendly dropdown labels

A Josh
Thread started by Alex.1. Contributors Josh.
Thread started
Last updated

What you’ll achieve

Let visitors choose a minimum and maximum difficulty using labels such as Beginner and Expert in the filtering controls.

My site

Platform
JReviews version

Replace a numeric search input with minimum and maximum dropdowns that display labels such as Beginner and Expert. JReviews searches the stored numbers between those choices, including both selected values.

This example uses jr_difficulty, an integer field with four stored values: Beginner = 10, Intermediate = 20, Advanced = 30, and Expert = 40. The labels never become the numeric field values. For decimal scales, choose enough decimal places to keep every grade distinct and ordered.

Prepare the numeric scale

Use a Route listing type for this example. Create a listing field group named Route details, or reuse a listing group already associated with Route. In Setup > Fields, create a listing Integer number field labeled Difficulty. In Name, type difficulty; JReviews adds the jr_ prefix, so the field name becomes jr_difficulty. Select Route details as its field group . In the Route listing type's Field Groups settings, associate that same group.

Keep Difficulty active and optional, with no dependencies. Give route submitters write access and visitors read access. Enable the field for advanced search. Authors enter a number in the listing form: 10 for Beginner, 20 for Intermediate, 30 for Advanced, or 40 for Expert. These are numeric inputs, not predefined field options. The dropdown labels below change the search controls, not the submission input.

Create four published Route listings named Beginner route, Intermediate route, Advanced route, and Expert route. Enter 10, 20, 30, and 40 respectively in Difficulty. Convert existing text grades before using numeric filtering. To use climbing grades instead, follow the optional encoding below.

Encode Yosemite Decimal System grades

Josh's climbing example uses a listing Decimal field labeled Yosemite grade, with the exact name jr_yds, so a numeric range can include grades with letters. Create it in Route details with seven decimal places. Keep the group associated with Route, and use the same permissions and advanced-search setting as Difficulty. Store the encoded numbers below; display the grade names in both minimum and maximum dropdowns. Use the same encoding when submitting listings.

Grade Stored number
Class 1 (Trail) 1.0000000
Class 2 2.0000000
Class 3 3.0000000
Class 4 4.0000000
5.0 5.0000000
5.1 5.0100000
5.2 5.0200000
5.3 5.0300000
5.4 5.0400000
5.5 5.0500000
5.6 5.0600000
5.7 5.0700000
5.8 5.0800000
5.9 5.0900000
5.10a 5.1010000
5.10b 5.1020000
5.10c 5.1030000
5.10d 5.1040000
5.11a 5.1110000
5.11b 5.1120000
5.11c 5.1130000
5.11d 5.1140000
5.12a 5.1210000
5.12b 5.1220000
5.12c 5.1230000
5.12d 5.1240000
5.13a 5.1310000
5.13b 5.1320000
5.13c 5.1330000
5.13d 5.1340000
5.14a 5.1410000
5.14b 5.1420000
5.14c 5.1430000
5.14d 5.1440000
5.15a 5.1510000
5.15b 5.1520000
5.15c 5.1530000
5.15d 5.1540000

JReviews 6 Early Access

Replace the numeric range inputs

Open the JReviews dashboard, select Manage Early Access, and turn on Listing List Pages if it is off. Create or retain a JReviews Advanced Search menu item or page so searches have a results route. Open its public page, select Route as the listing type, and run a search. Confirm that your four Route listings appear in the results.

In Setup > Site Widgets, create or edit a published Listing Filters widget. In its Filter Builder, add a Custom Field element and select Difficulty (jr_difficulty). A number field shows minimum and maximum inputs automatically. Leave Auto-detect from Page enabled for a Route category or search-results page. This example replaces that field's range inputs with Minimum and Maximum dropdowns.

Place a JReviews Universal Module on the search-results page. Select this published widget in JReviews Widget, choose the module position, and assign the module to the Advanced Search menu item.

Add a (JReviews) Universal Widget to a sidebar shown on the search-results page. Select this published widget in JReviews Widget.

Open that page and confirm that the Difficulty range control appears before applying the template override. See Site Widgets for the widget settings.

Copy the installed JReviews template resources/views/site/components/filters/elements/custom-field/range-input.blade.php into your overrides folder as resources/views/components/filters/elements/custom-field/range-input.blade.php. Create the missing folders.

Joomla. Copy the installed template from components/com_jreviews/resources/views/site/components/filters/elements/custom-field/range-input.blade.php. Use templates/jreviews_overrides as the override root.

WordPress. Copy the installed template from wp-content/plugins/jreviews/resources/views/site/components/filters/elements/custom-field/range-input.blade.php. Use jreviews_overrides as the override root.

Your copy gets two additions: a block at the very top and @endif at the very end. In the blocks below, the lines marked with + are the ones you add. The dimmed lines are already in the file and show where the new lines go.

  1. Add these lines at the very top of your copy, above its first line, @php:

    @if ($fieldName === 'jr_difficulty')
        @php
            $grades = ['10' => 'Beginner', '20' => 'Intermediate', '30' => 'Advanced', '40' => 'Expert'];
            $initialMinimum = in_array($operator, ['between', 'higher']) ? (string) $currentMin : '';
            $initialMaximum = in_array($operator, ['between', 'lower']) ? (string) $currentMax : '';
        @endphp
        <div x-data="{
            minimum: @js($initialMinimum), maximum: @js($initialMaximum),
            commit(which) {
                if (this.minimum !== '' && this.maximum !== '' && Number(this.minimum) > Number(this.maximum)) {
                    if (which === 'minimum') this.maximum = this.minimum;
                    else this.minimum = this.maximum;
                }
                this.$nextTick(() => this.$root.dispatchEvent(new Event('change', { bubbles: true })));
            }
        }" x-on:jreviews:filters:field-reset.window="if ($event.detail.field === @js($fieldName) || $event.detail.field === '*') { minimum = ''; maximum = ''; }">
            <label>Minimum
                <select x-model="minimum" x-on:change.stop="commit('minimum')">
                    <option value="">Any</option>
                    @foreach ($grades as $number => $label)
                        <option value="{{ (string) (float) $number }}">{{ $label }}</option>
                    @endforeach
                </select>
            </label>
            <label>Maximum
                <select x-model="maximum" x-on:change.stop="commit('maximum')">
                    <option value="">Any</option>
                    @foreach ($grades as $number => $label)
                        <option value="{{ (string) (float) $number }}">{{ $label }}</option>
                    @endforeach
                </select>
            </label>
            <input type="hidden" name="{{ $fieldName }}_operator" value="between" :disabled="minimum === '' && maximum === ''">
            <input type="hidden" name="{{ $fieldName }}[0]" :value="minimum" :disabled="minimum === '' && maximum === ''">
            <input type="hidden" name="{{ $fieldName }}[1]" :value="maximum" :disabled="minimum === '' && maximum === ''">
        </div>
    @else
        @php
            // The field title sits above the inputs, so they say only Minimum / Maximum.
    
  2. Add @endif at the very end of your copy, below its last line, </div>:

            </template>
        </div>
    @endif
    

Keep all the original contents between @else and the final @endif. They still render every other range field.

Choose Intermediate through Advanced. Results should include stored values 20 and 30 and exclude 10 and 40. Try a minimum only, a maximum only, and the filter's reset control. Selecting a minimum above the maximum moves the maximum up to match it. The filter submits numbers, not labels.

For the climbing grades in the table above, change the jr_difficulty field-name check to jr_yds and replace $grades with all entries from the table, mapping each stored number to its grade label. Keep seven decimal places in the decimal field. Use the same numbers when submitting listings; the dropdown cannot correct inconsistent stored values.

JReviews 5 and v6 Legacy

For the optional climbing scale, replace every jr_difficulty in the complete HTML below with jr_yds and replace the options in both dropdowns with this table's values and labels. Select the first grade for the default minimum and the last grade for the default maximum. Keep the hidden between operator, both visible dropdowns, and no blank option. For example, 5.10a through 5.10d searches from 5.1010000 through 5.1040000. Existing text grades need conversion before they can match these numeric filters.

Joomla. Use this example with the legacy Listings Advanced Filtering module. The steps call it the filter control.

WordPress. Use this example with the legacy Listings Advanced Filtering widget. The steps call it the filter control.

Prepare the field and filter control

  1. Enable that field for advanced search and configure JReviews Listings Advanced Filtering for the relevant listing types.
  2. Turn off live updates for this example. Keep the Search button so visitors choose both bounds before submitting.
  3. Create a JReviews Advanced Search menu item if you do not already have one.

Joomla. Assign the module to that results page as well as its starting pages.

WordPress. Make the widget available on the results page in the selected widget position.

Add the dropdowns to the filter form

Open the filter control's Theme Customization settings and turn on Enable Module Theme. Replace the generated filter for jr_difficulty with the complete block below. Keep the surrounding form, Search button, and filter settings. Remove the old filter token or generated input for this field so each request contains one operator and exactly two values.

If you maintain a template override instead, copy modules/filters.thtml from your installed legacy theme into your custom theme.

Joomla. Use templates/jreviews_overrides/views/themes/mysite/modules/filters.thtml.

WordPress. Use jreviews_overrides/views/themes/mysite/modules/filters.thtml.

Select mysite as your custom JReviews theme. Use Theme Explorer to confirm that the filter control loads that template.

<div class="jrFieldDiv jrDifficulty">
    <input type="hidden"
        name="data[Field][Listing][jr_difficulty_operator]" value="between">
    <label>
        Minimum difficulty
        <select name="data[Field][Listing][jr_difficulty][]" class="jrSelect" data-search="1" required>
            <option value="10" selected>Beginner</option>
            <option value="20">Intermediate</option>
            <option value="30">Advanced</option>
            <option value="40">Expert</option>
        </select>
    </label>
    <label>
        Maximum difficulty
        <select name="data[Field][Listing][jr_difficulty][]" class="jrSelect" data-search="1" required>
            <option value="10">Beginner</option>
            <option value="20">Intermediate</option>
            <option value="30">Advanced</option>
            <option value="40" selected>Expert</option>
        </select>
    </label>
</div>

The first submitted value is the minimum. The second is the maximum. between produces an inclusive numeric BETWEEN condition. An Intermediate-to-Advanced search therefore matches 20 and 30, not 10 or 40. Equal bounds search one level. A reversed range matches nothing, so keep the minimum at or below the maximum.

Both dropdowns have selected default values. Do not add a blank option. The legacy between filter requires both a minimum and a maximum. The default full range still excludes listings with no stored difficulty or values outside 10–40. Add a separate Clear filters link to the unfiltered Advanced Search menu URL you created. Open that menu item on your site, copy its public URL without any jr_* filter parameters, and use that URL for the link. This leaves the filtered results and opens an unfiltered search page. The built-in Reset handler does not reset these manually added dropdowns. Add this link beside the dropdowns in Theme Customization, replacing /advanced-search with that public menu URL:

<a href="/advanced-search" class="jrButton jrSmall">Clear filters</a>

With live updates off, opening the clean URL does not submit the dropdown defaults. The selected defaults apply only when the visitor submits another search.

The labels wrap their controls, so this markup needs no IDs and cannot introduce duplicate IDs when several filter controls appear on one page. The operator is hidden, while both bounds remain visible.

This static example returns to its HTML defaults when the whole form reloads. It does not restore selections from the search URL. Check the results URL to confirm the submitted range after a reload.

Check the results

On a test site, create four listings with the four numeric values. Search Intermediate through Advanced and confirm that only those two listings appear. Then test the same minimum and maximum, a minimum above the maximum, and the Clear filters link. Inspect the submitted request and confirm jr_difficulty_operator=between and two ordered jr_difficulty[] values.

Keep one filter control per form, and check both desktop and mobile layouts. If the old numeric input still appears, remove its generated field from the same form before testing again.

Learn more