Hello,
It's really a great idea to add a slider for numeric field with better exposed filters. However, I have some suggestions for an improved implementation.
It would be great to have only 1 slider for the "in between" operator (at lease as an option), like here.
Actually, this is not really user friendly to have a slide for the minimum range, and a slide for the maximum one.
In addition, it would be a good option to dynamically define the maximum range. I think most of users use that slider in a ecommerce project to filter price and it would be great to have a maximum range taking the value of the biggest price on the page because it's not really user friendly to have a $1000 maximum range in a page where the most expensive product is $20 (but you cannot put $20 as maximum range because you have some products that cost $1000 in some other categories).
Let's talk about these improvements.
Regards,
Alex
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | Capture.PNG | 1.8 KB | mikeker |
Comments
Comment #1
mikeker commentedAlex, thanks for starting the conversation.
That should be the default functionality for an "in between" filter:

If you're not seeing that, please open an issue and give the details of the field that's being exposed (or attach an export of the view). Thanks.
That would be a great improvement. While I could be done in the slider settings for that specific filter, it would have to be updated everytime a new, higher price item was added to the inventory.
My first thought is to allow token replacements in the slider settings. But I have no idea if Commerce (for example) provides a token for min- and max-price. If anyone can answer that, I'd appreciate it.
If there's no token option for min/max price, it could be something that a custom module does -- query the min/max prices and adjust
Drupal.settings.better_exposed_filters.slider_optionssettings. If you go that route, there may be issues around module weighting. If BEF is weighted lower than the custom module it will overwrite those settings. If that's the case, again please open another issue for that. I'm not sure if there's anything that can be done, but at least it'll be documented.Comment #2
mikeker commentedComment #3
mikeker commentedI just realized how easy this would be to do with an alter hook. So BEF now has a settings alter hook, which fires before the settings are used to customize any of the exposed form widgets.
So if you put:
in your theme's template.php (or in a custom module) you can alter the slider ranges using whatever logic you want. You'll need the latest -dev release for this.
Comment #4
thulenb commentedThat's a cool function and very helpful. Did somebody already manage to implement this?
I'm no coder but am I right that this
would only define the min and max as I can do in the settings. What would I have to add to use a DB query that determines the current min/max of a certain field?
Regards,
Thomas
Comment #5
mikeker commented@ThuleNB: That's correct, those would set the min/max values the same as you could in the BEF settings form -- perhaps not the best example... A better example would be to use a DB query to determine the current min/max values entered for a given field and use those for the slider min/max.
Comment #6
thulenb commentedOk, thank you. Is a DB query difficult to program? Is there something like a scheme where I can put my own values in it? Or is this not possible for a non-coder?
Comment #7
mikeker commented@ThuleNB: It all depends on the data you're querying. Unfortunately, there's not one single query that can be used for all field types. While it's certainly possible for a non-coder, it would be good to get some advice specific to your content schema and data. Probably best to post in the forums or on Drupal Answers.
Comment #9
kamranzafar commentedI want to update max based on another exposed dropdown field, is there any help for changing max value using js or jquery.
Regards,
Kamran Zafar
http://www.cognitiveaxis.com/
Comment #10
Seospan commentedHello !
A few weeks ago, I used the hook_better_exposed_filters_settings_alter(&$settings) suggested by mikeker.
But today, after updating my modules, it stopped working. The updates I did included Views (7.x - 3.8), could it be that ?
If somebody have the slightest idea...
Thanks !
Comment #11
Seospan commentedComment #12
thulenb commentedHello,
I am trying to use this hook function in order to get the min/max values from the database. As I am no coder I am facing some trouble with this and I couldn't get any useful answers in forums. Here's my approach:
At first I recognized that I don't have an own template.php in my subtheme folder. I copy pasted the original one in my subtheme folder and adjusted the name "bartik" everywhere into "new" (which is the name of my subtheme). Then I put the code in my template.php and changed "hook" into "new". Then I changed 'field_price_value' into 'field_price' (which is one of my fields). Just for checking I set the min and max values different from the BEF settings. I cleared all caches and refreshed my website but the min/max values didn't change. The original values from the BEF settings are still shown?
Does somebody see a mistake in this approach or what could cause this problem?
Thanks for any help in advance.
This is my code
Comment #13
thulenb commentedDoes somebody have an advice?
Comment #14
thulenb commentedDid something happen to the settings alter hook? After updating the module my function which has already worked doesn't work anymore:
Reverting back to a former version of BEF made it work again. Should I open a new issue for this bug?
Comment #15
guillaumehug commentedHi,
I think we need to implement a functionnality to refresh the min max values of other filters when we change a filter value.
It will be great to update the values of the current result.
With the hook_exposed_filters_settings_alter, it's not possible because it is executed before the view result, so we cannot execute sql to search the new min max following the other fields
Thanks
Comment #16
mikeker commentedReturns this issue to it's original status. If you're still having problems using the alter function, please open a new issues and provide as much detail about your config as you can.
@ThuleNB: Sorry for not replying earlier... Here's an example alter function that works for me:
Comment #17
firfin commentedIs this still relevant for D8? I opened a new issue for this, but no reaction so far.
Might be a duplicate of this though, so gonna mention it here anyway. #3006273: hook_better_exposed_filters_settings_alter not working for D8