The out-of-the-box numeric filters for range fields are not very useful. It would be great if there was a filter for which a single value could be supplied, and entities would match if the value was within range.

IE, entity A has a range field called some_field. The value is set from 25-50. Using a "Range" exposed View filter, I could submit 35 and it would return entity A whereas 60 would not.

CommentFileSizeAuthor
#5 Screenshot_20201112_151215.png67.32 KBint_ua

Comments

mstef created an issue. See original summary.

taran2l’s picture

Hi @mstef,

There are views normal and contextual filters that do exactly what you are asking for.

Best

mstef’s picture

How would you set that up with a single exposed filter?

taran2l’s picture

Status: Active » Closed (works as designed)
int_ua’s picture

StatusFileSize
new67.32 KB

Did you mean a built-in exposed filter? I don't see any reasonable settings for that one, it's just shown as a single numeric input that disregards value limits set for the range field, see the screenshot attached.

Did you mean another projects that provides a better default input? I can't find anything with "view filter range site:drupal.org" search request. https://www.drupal.org/project/views_numeric_range_filter is not what it seems and it's only for 7.x anyway.

taran2l’s picture

hi @int_ua, basically filter on the screenshot does exactly what this issue is about.

What's wrong with the settings? Why are they not reasonable/sane to you?

int_ua’s picture

I understand that you probably don't have time for this, but ideally I see it as a jQuery UI Slider with settings for min, max, step, values, range, maybe even custom handle with value displayed. Maybe it's already possible with Better Exposed Filters? But something is missing for that as I have BEF and jQuery UI Slider for Drupal installed. Does it have to be implemented in range or in BEF? For now I'll probably have to resort to custom twig template custom hook_form_alter.

In current state I don't see any effect of the "Include endpoints" setting but it's possible I misunderstood the meaning of it. And at least ability to set min, max, step, size and value HTML attributes of the default input type="number" from views filter settings would've been reasonable IMHO.

int_ua’s picture

Workaround module:

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_alter().
 */
function custom_numeric_filter_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $field = 'yourfieldname';
  if ($form_id == 'views_exposed_form' && array_key_exists($field, $form)) {
    $form[$field]['#step'] = 5;
    $form[$field]['#size'] = 5;
    $form[$field]['#min'] = 10;
    $form[$field]['#max'] = 60;
  }
}

int_ua’s picture

But I cannot change type this way. See https://drupal.stackexchange.com/q/298134/7177

taran2l’s picture

Issue summary: View changes

hi @int_ua, thanks for your suggestions. I think some of them does make total sense:

but ideally I see it as a jQuery UI Slider with settings for min, max, step, values, range, maybe even custom handle with value displayed.

jQuery UI is not supported anymore, the last release dates back to 2016. Also, it is deprecated for D8/9: https://www.drupal.org/node/3067969 Taking this into account, jQuery UI Slider won't be included in the module

Maybe it's already possible with Better Exposed Filters? But something is missing for that as I have BEF and jQuery UI Slider for Drupal installed. Does it have to be implemented in range or in BEF?

I'm not aware of any existing implementation of the in BEF

In current state I don't see any effect of the "Include endpoints" setting but it's possible I misunderstood the meaning of it.

Let's say there is a node with an integer range set to 5-7 and 5 has been selected as a value. With Include endpoints checked that node will be present (i.e. the condition will be FROM >= 5), otherwise - node will be filtered out (i.e. the condition will be FROM > 5). When using Range not contains filter everything is opposite

And at least ability to set min, max, step, size and value HTML attributes of the default input type="number" from views filter settings would've been reasonable IMHO.

Seems like a reasonable request to me. Could you create a new issue for that?

But I cannot change type this way. See https://drupal.stackexchange.com/q/298134/7177

Well, afaik it should work like that. Exposed form display is part of the core. Range module does not alter it in any way.

taran2l’s picture

Issue summary: View changes