Hi,
I'm building a view of homes/properties with exposed filters of "Minimum Rent" and "Maximum Rent" - so that people can find homes according to their budget.
Rent (per month) is basically an integer field and can be whichever number (£475 or £677 or whatever an end-user enters when creating the node). Right now in my automatically-refreshing exposed filters block I have "Min Rent" and "Max Rent" as textfields (Views won't allow anything else). The trouble is that if you are not typing "400" fast enough the view often refreshes with "4" or "40" = BAD user experience.
But in my exposed filters for "Min Rent" and "Max Rent" I want it to be a dropdown list of 100, 200, 300, 400, 500 etc -in other words, automatically fixed, so that it is quicker and user-friendlier to determine the min and max range. Exactly as we see on websites like www.rightmove.co.uk or www.zoopla.com or any other property listing website.).
It seems like it could be pretty easily achieved. I have come across a tutorial that does something similar here http://zugec.com/drupal/creating-custom-filters-in-views-2 and in this thread http://groups.drupal.org/node/25941 people are sugesting that it is possible to use hook_form_alter to achieve this.
I don't think I can achieve this with any other module and Better Exposed Filters seems to be the closest. If it works, it can have many-many other useful applications for filters that establish range like "minimum bedrooms" and "maximum bedrooms". "Min Price" and "Max Price" etc
The more I searched for a solution, the more I noticed that many people need this in one variant or another. So I thought why not turn to Better Exposed Filters module and ask them to make it available for Drupal community.
Feature request:
in Better Exposed Filters views-settings please give us a textarea where we can enter the values on separate lines (100, 200, 300, 400, 450, 500, 550 OR even texts like "Dogs", "Cats", "Foxes" or whatever) and the module will turn those textfield filters into a dropdown list filter with those values showing.
Comment | File | Size | Author |
---|---|---|---|
#26 | BEF.jpg | 66.5 KB | estevegri |
#24 | options.jpg | 77.23 KB | mazdakaps |
#17 | screenshot.jpg | 139.19 KB | a.ross |
#12 | dropdown_selection_filter_for_numeric_fields-1556670-12.patch | 4.05 KB | a.ross |
#10 | dropdown_selection_filter_for_numeric_fields-1556670-10.patch | 4.04 KB | a.ross |
Comments
Comment #1
drupalina CreditAttribution: drupalina commentedHere I'm attaching a small module called "Selectable Price" that I wrote to achieve this functionality for my "rentpcm" field. Works very well in D7 (but for some reason it also ads "No min" and "No max" boxes on all forms throughout the site including node creation forms and admin configuration forms). Maybe you could take it and incorporate its logic into your module for filters which establish the "in between" min and max range values.
So, what would be a cool feature for Better Exposed Filters (BEF) module for "in between" filters (where min and max range is established) is to have one textfield where admins could enter for example:
'0' => t('No Min'),
'100' => '100 pcm',
'200' => '200 pcm',
and another textfield where they could enter
'100' => '100 pcm',
'200' => '200 pcm',
'300' => '300 pcm',
'10000' => t('No Max'),
and then the BEF module would incorporate it into its code and create the effect like the above.
What do you think of the idea?
Comment #2
a.ross CreditAttribution: a.ross commented+1, need to achieve the same thing. Maybe I'll have a go at patching later.
Comment #3
a.ross CreditAttribution: a.ross commentedAlright, patch is done!
It's not ideal, in that it doesn't allow key|value pairs for dropdowns and you have to set a default option in a separate dialog (views' own filter configuration dialog). It works fine though, so please review!
Comment #5
a.ross CreditAttribution: a.ross commentedPatch failure seems to have something to do with line endings. We use windows at the office.
Here's a new patch, which actually supports key|label pairs, by utilizing the List module from core.
Comment #6
a.ross CreditAttribution: a.ross commentedChange to Needs review
Comment #8
junkbox CreditAttribution: junkbox commentedDrupalina,
Your module does the job nicely, the reason you're getting the min/max on all forms is because you're doing a generic form_alter (meaning all forms) what you're looking for is:
selectable_price_form_views_exposed_form_alter <--- at least for this application
Other than that, saved me a lot of time thanks!
Comment #9
mazdakaps CreditAttribution: mazdakaps commentedIs there any update on this? Also drupalinas module how can i make it work? I created a module with drupalinas code i enable it at modules section but after that i dont know what to do.
Thank you very much
Comment #10
a.ross CreditAttribution: a.ross commentedRe-rolled my old patch. Hope this one at least applies.
Comment #12
a.ross CreditAttribution: a.ross commentedUgh. DOS line endings yay...
Comment #13
a.ross CreditAttribution: a.ross commentedComment #14
mazdakaps CreditAttribution: mazdakaps commentedHello i just run the patch . If i didnt do something wrong i selected for the price filter the drop down with preset values. The problem is that i dont know how to insert the preseted values so the drop down menus are empty.
Thank you
Comment #15
a.ross CreditAttribution: a.ross commentedIt works just like a regular list field. Here's an example of input:
10|$10,-
50|$50,-
100|$100,-
You should also set the default value of the dropdown in the Views' filter, otherwise you'll get an error.
Comment #16
mazdakaps CreditAttribution: mazdakaps commentedI am sorry but i didnt understand
i created a filter the field_price and i use is between i insert one min and one max value but i dont understand where to insert the values for the list field
10|$10,-
50|$50,-
100|$100,-
Sorry again but my brain stucked
Comment #17
a.ross CreditAttribution: a.ross commentedIt's under 'More options for "Price"'
Comment #18
mazdakaps CreditAttribution: mazdakaps commentedHmm thats why i cant insert the values. I selected the drop down but these options i see in the photo are missing. Ill try to patch it again and ill inform you.
Cheers
Comment #19
mazdakaps CreditAttribution: mazdakaps commentedok i repatched it, followed your instructions and it seems that is working. I will test it and ill inform for any issues.
Thank you very much
Comment #20
mazdakaps CreditAttribution: mazdakaps commentedOne thing in dont know if it is a bug if i punt the values and i want to change them again when i go to change them the values arent there anymore
Comment #21
a.ross CreditAttribution: a.ross commentedDid you input the default value in the normal Views filter dialog?
Comment #22
mazdakaps CreditAttribution: mazdakaps commentedyes in the normal filter dialog i insert the min and max values because if i dont it gives me an error. It isnt that is not working but if i want to make changes of the values of the dropdown even if it works the values arent there anymore and i have to put them again.
Comment #23
a.ross CreditAttribution: a.ross commentedIt works for me. Can you paste your options?
Comment #24
mazdakaps CreditAttribution: mazdakaps commentedOk in the picture i you can see the option boxes without the options inside even if it works after i insert the option when i go there to make a change there isnt anything there for some reason.
The options i user is something like yours in your picture
0| Min
1000
2000
3000
4000
5000
and
99999999| Max
1000
2000
3000
4000
5000
Comment #25
a.ross CreditAttribution: a.ross commentedAhh, alright. That's quite strange, and I can't seem to reproduce it... :/
Can you find the following line in: better_exposed_filters_exposed_form_plugin.inc
$bef_options[$label]['more_options']['bef_numeric_list_0'] = array(
and put the following before it:
dsm($existing[$label]);
Install the devel module and see what output you get when you open the BEF dialog.
Comment #26
estevegri CreditAttribution: estevegri commentedHello. This is the fisrt time that I write here, so I'm sorry if I make any error in this message.
I'm using Drupal 7, Views 3 and BEF.
I have an exposed filter in views that have an integer field where I insert prices. That filter is "in betwen" mode. I would like to make this exposed filter as a dropdown.
First question: I copied the code of the patch #12 at "better_exposed_filters_exposed_form_plugin.inc", but I'm not sure where I have to insert the third part of that code. I mean the last part of code that starts with:
+ case 'bef_dropdown':
+ if (!module_exists('list')) {
+ break;
+ }
+ $formfield = array(
...
In any case, I can choose dropdown in "BEF settings / exposed filter settings" for the price field, but I can't see the textareas where I have to insert the two list of prices for min and max prices. I have attached a screen of "BEF settings". If I save these settings, then I see the filter with dropdowns but without any value to choose. Additionally, If I return to the "BEF settings / exposed filter settings", the price field settings is configured to "Default numeric field" again.
I would appreciate any help.
Thanks a lot.
Comment #27
a.ross CreditAttribution: a.ross commentedRead this to learn how to properly apply patches: http://drupal.org/patch/apply
Comment #28
estevegri CreditAttribution: estevegri commenteda.ross, thanks and sorry for my basic question.
I applied correctly the patch and seems that it is working fine. As said in #13 I set the default min and max values of the dropdown in the Views filter (thanks again a.ross).
But now, I get an issue with the conditional fields module. I would like to make the min and max exposed filter dependent to another filter. I created the dependencie like always but it is not applied. The min and max exposed filter is always showing. Any ideas why?
Thanks a lot
Comment #29
a.ross CreditAttribution: a.ross commentedHm, as far as I understand, Views support in Conditional Fields is still under development: http://drupal.org/node/961406
Regardless, that could be a pretty hard-to-fix issue.
Comment #30
dgastudio CreditAttribution: dgastudio commentedcan this patch be migrated to latest stabe version of BEF?
u5444@krypton ~/domains/auto.u5444.krypton.vps-private.net/sites/all/modules/bet ter_exposed_filters $ curl http://drupal.org/files/dropdown_selection_filter_for
_numeric_fields-1556670-12.patch | git apply
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
101 4148 101 4148 0 0 8506 0 --:--:-- --:--:-- --:--:-- 13168
error: patch failed: better_exposed_filters_exposed_form_plugin.inc:296
error: better_exposed_filters_exposed_form_plugin.inc: patch does not apply
Comment #31
dgastudio CreditAttribution: dgastudio commentedok, applied the patch to beta 3 version, works perfectly except the same problem as in #24.
up. it's becouse $existing is empty.
Comment #32
a.ross CreditAttribution: a.ross commentedAs I expected. I wouldn't know why $existing is empty though. Maybe the variable name was changed? In any case, I don't think I will be able to support this patch any longer. I hope someone else takes it and improves upon it. I'd like to see this stuff committed.
Comment #33
dgastudio CreditAttribution: dgastudio commentedi have found the problem
simply replace $existing with $this->options['bef'].
Comment #34
mikeker CreditAttribution: mikeker commentedApologies for letting this sit for so long. I'll try and review it in the next week.
Comment #35
a.ross CreditAttribution: a.ross commentedThat would be great! :)
Comment #36
mikeker CreditAttribution: mikeker commented@a.ross, I appreciate the time and effort you've put into this issue, but I'm going to postpone as #731662: Hybrid Exposed Filters has been in the Views -dev releases for for a couple months now and will offer more flexibility once they add greater/less than options. (I didn't know about it until I had to debug a Views' bug and pulled the latest code from Git or I would've mentioned this earlier.)
Granted there are a lot of bugs with the current implementation of Grouped Filter (aka Hybrid Filters) at the moment, but I think it'll be a better solution eventually.
Give Grouped Filters a try and feel free to reopen this issue if you feel otherwise.
Comment #37
a.ross CreditAttribution: a.ross commentedWhoa! That's an interesting issue. Looks like it's already in the stable release as well! Good find.
Comment #38
dgastudio CreditAttribution: dgastudio commentedmaybee you are right, but remember that with new hybrid filter you can only populate value "equal to", not range.
i mean, with this patch, i can prepopulate values for "BETWEEN" value.
and really need it.
sorry for my english.
Comment #39
a.ross CreditAttribution: a.ross commentedAh, I see what you mean, as the end user, you get a dropdown for both the "from" value and the "to" value, a different solution to the hybrid filters in Views, which you can use to make a preset, such as: Between 10 and 100, between 100 and 1000.
Comment #40
dgastudio CreditAttribution: dgastudio commentedyes, you are right.
i have applied manually the the patch and it works perfectly.
the only thing that will be really cool, is if we can enter KEY / VALUE in lists instead of only KEY
i mean.
now for example, to set price range i have to :
100
200
300
with key value feature, it will be
100|100 $
200|200 $
300|300 $
Comment #41
a.ross CreditAttribution: a.ross commentedThis should already be possible in fact :)
It does require enabling the List module from core iirc. Maybe just the Options module.
Comment #42
ensignavenger CreditAttribution: ensignavenger commentedI have applied this patch it it appears to work quite well! I looked at the solution in #36, but I did not want to use the dev version of views on my site, and it appears to be not quite ready, whereas this patch seems to work much better.
One question, in several comments, setting the default value is mentioned- but how exactly do you do that? I suppose this is more of a views issue, as it has to be done in the regular views filter dialog- but I can't seem to find where or how, and my problem applies directly to getting the patch to work properly, so I thought I'd mention it here!
Comment #43
ensignavenger CreditAttribution: ensignavenger commentedNever ceases to amaze me- I search and search for a solution, and then I post asking others- and then I find the answer!
My problem was I had put a value into the filter box for the default that was not used as an option for the select box- and thus it could not be the default...
Thanks for the great patch!
Comment #44
johnhorning CreditAttribution: johnhorning commentedI was about to ask what the status of this is, but then discovered that this feature is now built into views and called grouped filters.
Comment #45
Neslee Canil PintoHi, there will be no more future development for 7.x branch. If you see this issue in 8.x, feel free to file an issue. Closing this as Closed(wont fix).