It would be great to have the select drop-down exposed filter for provinces instead of autocomplete textfield. In some cases it can be found to be more convenient to select the province using the mouse instead of typing some letters in the autocomplete field. Is there any way this could be possible to be done with the latest location releases?
| Comment | File | Size | Author |
|---|---|---|---|
| #64 | location-dropdown-filter-330066-64.patch | 3.47 KB | w00zle |
| #40 | location-province_filter_dropdown-330066-40.patch | 3.4 KB | agileware |
| #28 | location_province_filter_dropdown.patch | 3.26 KB | edmund.kwok |
Comments
Comment #1
evave commentedComment #2
mtndan commentedI'm also very interested in this issue - any help would be appreciated!
Comment #3
raspberryman commentedI don't know how the module could support select dropdowns for states/provinces. With all the state provinces in the world... it could get crazy.
Anyways, I did need this functionality for a client, so here is my solution:
Comment #4
dubios commentedThank you very much, you're my drupal guru, that was incredibly useful.
Comment #5
sankar_jeya commentedThanks for giving this idea will u plz tel how to work on drupal6 since i have tried tis code not working i have used this in view expose filter for location
Comment #6
raspberryman commentedThe code is definitely a hack and may need some customization to get it working. The code above was used for Drupal 6.
mysite_form_altershould be renamed to use your site's custom module name,myviewnameshould be the name of your view,location_get_provinces('us')should be set to the country you want to use, and you may need to use devel.module'sdpmfunction to verify that$form['#parameters'][1]is your views object.Comment #7
sankar_jeya commentedthanks ..
Comment #8
neokrish commentedI need a list box with multiselect facility for province. How do I hack this code to achieve this?
I tried your code by changing the above to something like this,
I know I am making many blunders here, but any pointers on how to proceed will be greatly appreciated. I need this code for one of the projects that I am currently working on.
Thanks for any help,
neokrish
Comment #9
yesct commentedtagging
Comment #10
Xabi commentedSubscribing.
Comment #11
Drupal-Tech commentedsubscribing
Comment #12
smithn.nc commentedSubscribing. It would make a lot of sense to have this as a standard option for Location's Views interactions. Most site visitors expect State/Province selection to be done via drop-down.
Comment #13
mcaden commentedI used this variation of raspberryman's code to make the "province" field on every view a dropdown:
(in mymodule_form_alter)
EDIT: Added 'Any' to the filter list, otherwise it will always filter by a state. This makes filtering by state optional.
Comment #14
alextronic commentedHey Raspberry, first of all Thanks for your code, it seems that it works for some people; I'm trying to have a State/Province dropdown in one of my Views (via Location module). I'm on D6, and have the latest versions of Location and Views 2.
But I'd really be very thankful if you could ellaborate a little more on how to use that hack since I still can't figure out how to implement it... I'm not good at custom modules but if you could provide me a very simple step-by-step on how and where to use that piece of code I'm sure I could use it.
Thanks in advance so much.
Alex.
Comment #15
mcaden commentedThe general consensus is to make your own module per-site that has all your customization in it: http://drupal.org/node/206753
Then paste the function to add:
Then create a function called mymodule_form_alter, replacing mymodule in the function name with the name of the module you just created, and within that function paste:
Comment #16
alextronic commentedSee next comment.
Comment #17
alextronic commentedOK I made it! ...But a new problem has arised. Bear with me for a minute.
This is my provincedropdown module:
...and this is what I inserted into views.module:
And now, on the exposed filter for my view, I (finally) can see a dropdown select list for the US states. But, when I select a State and click on the "Apply" button to filter the View, it goes to the URL:
http://www.example.com/?title=&province=Delaware&field_field1_value_many_to_one=All&field_field2_value_many_to_one=All(home page, of course)So, it would be necessary to fix 2 things:
1) First item in select list: - Any -
2) On applying exposed filters, display new View correctly.
Anyone?
Thanks so much in advance.
Alex.
Comment #18
mcaden commentedNot sure why your query is messing up. I don't have that problem with the code I pasted and I don't see anything particularly wrong with your code
provincedropdown_form_alter should go in provincedropdown.module - it's a hook. By putting this function into your module hooking into views from your module. Otherwise you'd just edit the views code which would be a hack and make it a royal pain to upgrade drupal later. Additionally, if look look at my version of select_province, you'll see that I added "Any" to the options.
Comment #19
alextronic commentedI also don't know why, really.
I had to change the way of embedding the View into my custom template using this code:
Anyway, thank you very much.
A.
Comment #20
juicytoo commentedsubscribing
Comment #21
edemus commentedi just wanted to share with others, because it took me a while to figure this
In function:
on line
$form['province'] states for filter identifier in Views. province is default which, in most cases its ok, but not for me. I had two views in bundled in Quicktab tabs, and both had filter identifier set to "province" which happen to work with only one view, the other didnt work, which causes unwanted results.
The thing is to use different filter identifiers, but only if you plan displaying more than one view on the same page simultaneously.
For the record :
Hope this helps someone
edit: Forgot to thank to author. You really saved my day.
Emil
Comment #22
compujohnny commentedThis Code did not work for me in case the user just clicked apply without selecting anything, province "Any" returns empty
I fixed it by changing
to
Here is the fixed code
Comment #23
czeky commentedHi, this is very helpful post, can someone explain, how to identify and use fields? I'd like to override exposed view.. I need to limit exposed operator to "is less than or equal" or "is greater or equal"
thanx
Comment #24
Anonymous (not verified) commentedShould this feature request be updated to Version 6.x?
-subscribing-
Comment #25
kruser commentedSubscribing - Looking for a D6 fix.
Comment #26
clashar commenteddropdown is better for sure
subscribe
Comment #27
clashar commentedComment #28
edmund.kwok commentedAh, it just so happens that a client's site would benefit from this feature so I went around coding this. Attached patch adds an extra option for the Province filter - either Dropdown or Autocomplete. Similar to how Taxonomy: Term filter works.
Please test :)
Comment #29
clashar commentededmund.kwok,
I applied patch to "location_handler_filter_location_province.inc".
Dropdown and autocomplete options now appears on filter creation form.
But if dropdown is chosen, then the filter is not displayed on the result page, nor even on preview. Even if I change it autocomplete, filter is not displayed.
So I should delete created dropdown filter, save view and then create new autocomplete filter.
Comment #30
bryancasler commentedsubscribe
Comment #31
Anonymous (not verified) commentedI applied the patch but can't figure out where the "Dropdown or Autocomplete" configuration option is.
Tried
admin/content/types/.../fieldsandadmin/settings/locationbut nothing there. Can you specify where is this option?Thank you.
Comment #32
pog21 commentedI can't find it either. Does anybody know where it is?
Comment #33
BrockBoland commentedPatch in #28 looks good and works for me.
For those looking for the option it adds: this is only in Views. If you already have the Province filter enabled in your View, click the gear icon to the right of it to toggle between the Dropdown and Autocomplete options.
clashar, it sounds like you need to edit the filter and click the Expose button to show the dropdown. Only exposed filters are shown in the preview and on the actual view.
Comment #34
pog21 commentedThanks BrockBoland. Patch in #28 now working.
But there's one more thing. Is there a way to update the province list when a country is selected? At the moment the province field does not change when I select a country. Instead I have to choose the country, click submit, then choose a province.
Comment #35
stoptime commentedPatch seems to be working - thank you very much!
Comment #36
alb commentedregards the patch;
the province is filled with the correct values only after click the send button (so only after the page is reloaded );
this isn't good,
is possible to fill the select's province in the moment that is selected a country?
see that province's values are read in the database and this is slow;
there is already a solution for read the value not in a db;
I think better solution is read by a js file;
is possible to do this?
Comment #37
pog21 commentedChanged to active. Not sure if this is correct usage, so let me know if I should start a new issue instead.
Comment #38
mototribe commentedsubscribe
Comment #39
agileware commentedNeeds work as there is a valid patch in #28 that needs a little extra.
Seems like it would just need a fix for the issue mentioned in #34 & #36.
Comment #40
agileware commentedHere is the patch from #28 with a minor change (the default value of the select field).
Still doesn't fix the issue mentioned in #34 & #36 though.
Comment #41
agileware commentedStill having a problem on initial load where you get the error:
"An illegal choice has been detected. Please contact the site administrator." because the value is empty.
Comment #42
bryancasler commentedThanks so much for doing this Agileware. Do you have any plans to patch against the D7 version?
Comment #43
see15_aug commentedThanks it's working for me.
For other countries use iso abbreviation for country name at
$provinces = location_get_provinces('countryname');
Comment #44
thepanz commentedI'm coding a fix for #34 : AJAX fetching of provinces on Country change... based on Agileware patch.
I'll post it in a few days...
Comment #45
thepanz commentedComment #46
ankur commented@thePanz
You wouldn't be open to also posting a 7.x-3.x version of the patch, would you? :-)
I'd review and commit it if you were.
Comment #47
thepanz commentedHi @ankur ..are you the Ankur I "stole" TrackBack module from? ;)
My edits to 6.x-3.x version aren't big, I think porting to Views 3 should not be so hard.. even if I never worked with Views3 yet!
I'll post my patch in few days
Comment #48
thepanz commentedAs promised: the attached patch allows to have a SELECT field in a View filter.
The Patch includes my other fix for #1443240: Province SELECT auto-update not working without clean-urls.
Hope Ankur will commit it :)
Unfortunately I don't have time to port it onD7 or Views3 :(
Comment #49
Johnny vd Laar commentedFor drupal 7 I created an extra views filter that is a child of the allready existing province filter in a separate module.
So make sure that in your module you have this in your info file:
files[] = includes/location_handler_filter_location_province_select.incMake sure that you have this in your hook_views_data
This gives you a new views filter
Comment #50
pog21 commentedThanks for the patch in #48. But having a bit of trouble applying with terminal (mac). Haven't applied many patches this way before, but seems like a lot of changes to do manually. I get this output:
Is there something I should be doing differently since it changes 4 files?
Cheers,
Oliver
Comment #51
ionz149 commented@pog21 I was having the same problem and I was able to apply the patch successfully by using -p1
ie: patch -p1 < filename.patch
it was on this page: http://drupal.org/node/707484
Comment #52
pog21 commented@ionz149 Thanks! That was it.
Oh, and thanks to thePanz, too. :)
Comment #53
see15_aug commenteda
Comment #54
see15_aug commentedComment #56
BrockBoland commentedComment #57
BrockBoland commentedComment #58
32i commented@thePanz I took latest location 7.x-3.x-dev versino and manually added changes suggested by you and managed to have the province as dropdown. However, I did not found some of JS changes - actually haven't looked at it too much. I'll test if it's working ok in next few days and I guess I'll provide a patch for 7.x
Thanks for your work, anyway.
Comment #59
mrweiner commented@32i: A patch for 7.x would be greatly appreciated. :)
Comment #60
32i commentedPlease find attached, Province/state filter as dropdown for 7.x.
I used location 7.x-3.x-dev (released April 21), however patch should apply to any 7.x version.
Comment #61
mrweiner commented@32i: Patch works perfectly. Thank you so much!
Comment #62
simon_s commented@32i: Patch #60 works also fine applied on 7.x 3.x-dev from 2012-May-05. Thanks!!!
Comment #63
energee commentedRerolled against latest production release (July 25th 2012)
Comment #64
w00zle commentedI had two issues with the patch from post 63:
1. The file path was hard coded to /Drupal/sites/all/modules/contrib/location/handlers/location_handler_filter_location_province.inc, so cloning the repo and then applying the patch failed the first time I tried.
2. The "Allow Multiple Selections" value for the exposed filter was not being passed, so you could only filter by one value at a time.
I believe I have fixed both of these issues in this patch. Please let me know if anything looks wrong or doesn't work.
Comment #65
ZoodaVex commentedThank you for the patch, it works fine for me on 7.x-3.0-a1.
I noticed, however, that Better Exposed Filters does not recognize the new province dropdown as a dropdown that may be "bettered", but treats it as an autocomplete. Is there a way to make BEF recognize province dropdown?
Comment #66
mattbk commentedDid this patch ever get incorporated into the module?
Comment #67
podarok#1931088: [META] Fixing tests tests were broken, so triggering to active
Comment #68
podarokbot
Comment #69
podarokFor get this feature commited I have to know what patch is the TRUE
please, point me to it
Comment #70
yaelsho commentedHello,
Did someone succeed to resolve the issue mentioned in #36?
Thanks, Yael
Comment #71
yaelsho commentedAnyone?
Comment #72
lukio commentedHi podarok!
I apply the patch #64 against 7.x-3.0-rc3 and the patch pass and works. Hope you can commit the patch.
Comment #73
comradebeck commented#64: location-dropdown-filter-330066-64.patch queued for re-testing.
Comment #74
podarok#64 commited pushed to 7.x-3.x-dev
Thanks!!
Comment #75
comradebeck commentedWhen you show the exposed filter form on a block, the ajax to call corresponding provinces from a selected country is not working.
Any thoughts why????
Comment #77
pog21 commentedI have exposed filters in views, one of the views in a panel the other just a view page. In both cases, the form needs be updated after choosing a country before the province field updates.
Reopening this issue, but I did get a bit confused about the goal of this issue halfway down, so if the current issue is only about adding drop down functionality and not making it automatically update when a country is chosen, let me know and I'll create a new issue. If the automatic update part has been addressed/fixed, I'd also like to know as it's not working for me! :)
Using 7.x-3.x-dev.
Comment #78
pog21 commentedComment #79
podarokBetter create follow-up child issue
This one is from 2008... Long time ago...