Check or uncheck every option in a field
- Thread started
- Last updated
What you’ll achieve
Add selection controls above a checkbox custom field.
My site
Add controls that select or clear every option in one checkbox custom field. For example, a booking form with a checkbox field for each day can let the owner select all time slots for one day with one click. Add the controls separately to each day's field so other days keep their selections.
JReviews 6 Early Access
Enable Listing Form in Early Access before adding this customization.
Add the PHP code to your overrides
Joomla. Add the PHP example to templates/jreviews_overrides/hooks.php.
WordPress. Add the PHP example to jreviews_overrides/hooks.php.
Start a new file with <?php followed by defined('MVC_FRAMEWORK') or die;. If the file exists, append the registration without repeating those lines. Keep the customization in overrides rather than editing JReviews core files.
Add controls for one checkbox field
Use a checkbox custom field named jr_amenities in this example. If your field has a different name, replace every jr_amenities in the code below with its saved field name.
The code places the buttons immediately before that field in the listing form. Each button changes only that field's available checkboxes and tells JReviews to update fields that depend on those choices.
fwd_add_action('jreviews:listing_form.before_field:jr_amenities', function ($field, $listing, $fieldGroups): void {
echo <<<'HTML'
<div data-guide-checkbox-controls>
<button type="button" class="fwd-text-link" onclick="this.closest('form').querySelectorAll('input[type=checkbox][name="fields[jr_amenities][]"]:not(:disabled)').forEach(input => { if (!input.checked) { input.checked = true; input.dispatchEvent(new Event('change', {bubbles: true})); } })">Check all</button>
<span aria-hidden="true"> · </span>
<button type="button" class="fwd-text-link" onclick="this.closest('form').querySelectorAll('input[type=checkbox][name="fields[jr_amenities][]"]:not(:disabled)').forEach(input => { if (input.checked) { input.checked = false; input.dispatchEvent(new Event('change', {bubbles: true})); } })">Uncheck all</button>
</div>
HTML;
}, 20, 3);
Dependent fields receive the same change notification as when a visitor selects or clears each checkbox individually.
Test selection and dependencies
Open a new listing form and click both controls. Only this field must change. If an option controls another field, check that the dependent control appears or disappears after the refresh. Save, reopen the listing, and check the selected values. Test a field with no selected values and a second checkbox field in the same form to confirm the buttons do not change it.
JReviews 5 and v6 Legacy
Add Check all and Uncheck all controls above a checkbox custom field so visitors can select or clear its options together in the submission form.
Add the field controls
Paste this HTML into the checkbox field description. Configure the description to appear above the field. The page must load jQuery and preserve the inline click handlers.
<a class="jrButton jrSmall" onclick="jQuery(this).parents('.jrFieldDiv').find('input').prop('checked',true).trigger('change')">
Check all
</a>
<a class="jrButton jrSmall" onclick="jQuery(this).parents('.jrFieldDiv').find('input').prop('checked',false).trigger('change')">
Uncheck all
</a>
Test that only this field changes
The controls act on checkboxes inside the same field container, named .jrFieldDiv in the page HTML. That container must contain only the options you want these buttons to change. Other fields must remain unaffected in the check below.
Open the submission form and click each control. Check all should select every option in that field, and Uncheck all should clear them. If other fields depend on those options, confirm that they update too. Each checkbox triggers its normal change event.
Learn more
- Custom Fields (v5)
- Custom Field PHP Formatting (v5)
- Custom Fields (v6)
- Custom Field Output Formatting (v6)
- Hooks (v6)
- Themes and overrides (v6)