Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 301123

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

$
0
0

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!


Viewing all articles
Browse latest Browse all 301123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>