Exposed filter using checkbox always checked (e.g. history is-new)

Created on 9 June 2016, about 8 years ago
Updated 30 May 2024, 3 months ago

I'm trying to create a Views filter plugin which shows a checkbox, and seeing some odd behaviour:

1.
My own custom code works with submitting the form: I correctly get 'key=1' in the URL query when I submit with the checkbox selected. What doesn't work is the default value of the filter: when this is set to enabled by default, the first load of the view does not have the checkbox selected. I can't figure out why -- hook_form_alter shows me the checkbox form element has a #default_value => 1 as expected, but the produced HTML form element is missing the checked="checked" attribute.

2.
In an attempt to figure out if this was a core bug, I temporarily hacked the BooleanOperator filter plugin to make it show a checkbox:

    if ($exposed = $form_state->get('exposed')) {
      // Exposed filter: use a select box to save space.
      $filter_form_type = 'checkbox';
    }

I made a test view with the node status field exposed.
This *does* correctly show the default value for the filter. But when I submit the exposed form, no matter whether the checkbox is selected or not, it always reloads with the checkbox selected. The URL query looks right though. In other words:

- select and submit: result URL ?status=1, checkbox selected
- unselect and submit: result URL has no query string, checkbox selected!

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 11 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024