Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi there,
I have a problem to get the date popup module working the way I need. The popup works in every field, which is no exposed filter. But now I have a view with an exposed filter. I selected the option "popup" in the exposed filter options. The popup-field is working, but with the wrong format. I need the format "d.m.Y", but the displayed format is "y-m-d". What have I done wrong? Is there any option I haven't seen? Or is it a problem in the views-module? In that case I beg your pardon and create a new issue ;)
Thanks so far,
Tharya
Comments
Comment #1
jaxtheking CreditAttribution: jaxtheking commentedThat's true! I did not even notice when a client pointed this small but annoying issue. I found a possible solution here, I will let you know if this fixes it (in the short term). It would be great if we could sort out this. GREAT GREAT module by the way.
http://clipmarks.com/clipmark/DF28954C-0291-4C88-ABF9-F9C647171F4C
Comment #2
jaxtheking CreditAttribution: jaxtheking commentedThe link above actually did work - it's a hack though :(
Comment #3
aelling CreditAttribution: aelling commentedI am also having this issue with Date 6.x-2.x-dev and views 6.x-2.10. I really do not want to hack the module as it will make updates more of a pain. Is there anyway to override this correctly?
Comment #4
djschoone CreditAttribution: djschoone commentedalso interested in doing this a clean way!
Comment #5
aelling CreditAttribution: aelling commentedWhat we ended up doing was creating a custom module that did a hook_form_alter on the exposed views form filter. Below is an example of the code we used in our .module file. We were doing a filter by date range thus the code is written for both the min and max field filters.
Comment #6
YK85 CreditAttribution: YK85 commentedsubscribing
Comment #7
mansspams CreditAttribution: mansspams commented#5 works!
It actually fixes another problem - date field is now populated with proper relative values. have no idea why, maybe my defaults for field and for views were off. Thanks aelling!
Comment #8
mansspams CreditAttribution: mansspams commentedok, maybe not that loud, sorry
Comment #9
mkahn CreditAttribution: mkahn commentedI have a problem which isnt quite this one, but is closely enough related as to draw attention from the same users, I'd guess.
my exposed filter is generating args like ?q=Cal&date_filter[value][date]=2011-02 ; which are not getting interpreted by drupal as arguments that can be used by my views.. if i construct my own args (?q=Cal/2011-02) it works fine.
Any support is appreciated. Ive been banging my head for a while.
Thanks!
Mark
Comment #10
tezalsec CreditAttribution: tezalsec commentedI am trying to accomplish the same thing, but I can't get #5 to work, and I have really no idea why ;-(
This is my code:
The if condition returns true, so the id is correct, and it has to be related to what happens next..
Could it be because it is built within a panel? I should also note that I am using popup calender in these range fields.
Any suggestions? Thanks
Max
Comment #11
ruslan.muradov CreditAttribution: ruslan.muradov commentedMaxim75
I have placed code from above in general form_alter handler (i.e. in mymodule_form_alter) and everything works fine. Code looks like
Beside of this, are you sure that your exposed date filter has identifier 'date_filter_1' ? You can watch the identifier of your filter by clicking on filter in view configuration page. There should be Filter identifier input - copy the value of filter identifier from that input
Cheers.
Comment #12
tezalsec CreditAttribution: tezalsec commentedThanks a lot, Ruslan!
I got it working. you were right, my bad...
I used the native id where in an ancient past I had configured it with an overriding id, with this all is well ;-)
Cheers!
Max
Comment #13
add1sun CreditAttribution: add1sun commentedComment #15
awm CreditAttribution: awm commentedI am encountering this same problem in Drupal 7. I cannot configure the date format in the exposed filter with Popup calendar. It only goes by YYYY-MM-DD where the date field I created goes format like Jun 22 2011.
any solution without having to use form_hook_alter?
Thanks
Comment #16
enboig CreditAttribution: enboig commentedI have created two form_alter's to achive this. Now the date format in views filter is configurable. I hope this functions could enter date_popup module....
Comment #17
Dustin Currie CreditAttribution: Dustin Currie commentedI've updated the snippet above for views 3.x
Comment #18
hlykos CreditAttribution: hlykos commentedsubscribe
Comment #19
dmitrii CreditAttribution: dmitrii commentedenboig, thank for your code.
it helped me with some revisions:
Comment #20
nixar CreditAttribution: nixar commentedI believe #17 is exactly what I need but I can't figure where I need to insert similar code to make it work.
My filter date_filter only accepts 'Y-m' and I need it to accept a 'F Y' format.
Do I have to create a custom module to do that?
This is the last hurdle of my first Drupal7 website!
Comment #21
tomsm CreditAttribution: tomsm commentedInsert the code in a custom module.
For example: create a folder "mymodule" in sites/all/modules and add two files:
; $Id: mymodule,v 6.x-dev 2011/10/20 16:45:57 tomsm $
name = My module 2
description = My custom module to alter the date format in views filters
package = Custom modules
core = "6.x"
version = "6.x-dev"
Replace 'views-exposed-form-order-panel-page' with the id of your view. You can use firebug to determine what that is.
Activate your custom module and clear all caches and the date format should change.
Comment #22
nixar CreditAttribution: nixar commentedThank you tomsm very much for your input.
I did what you suggested but it doesn't work on my dev site. EDIT: After a little more fiddling, it does work - see below
I made sure everything is setup fine in the 5-line function but my filter will only accept 'Y-m' and not 'F Y'.
Now, maybe this is where I got it all wrong. My filter is not displaying any values, it's just a text input box in which users type a date like 'May 2005', 'May' or '2005'. So maybe I'm not seeing the result of my custom module.
I think maybe I got confused and what I want is not to display a date in a different format but for the filter to accept a different format. How should I go about that?
Thanks to anyone who will help me being a better hmm drupalist
N
EDIT: I forgot to enable the Date Views module which is why it wouldn't work. All is well now!
Comment #23
Parkes Design CreditAttribution: Parkes Design commentedSubscribe - Thank you very much guys solution 16 was the easy fix.
Comment #24
Striknin CreditAttribution: Striknin commentedHi,
I can't fix this using D7, views 3 and Date 7.x-2.x-dev version.
When I expose my date filters, they still are in 'Y-m-d' format.
There is any way to do this in D7?
The solution in #21 didn't helped me, here is my code :
module : date_fixed_format
Someone can say me how to format my exposed filters with date popup ?
Thanks
Comment #25
KarenS CreditAttribution: KarenS commentedPlease please please don't reopen closed issues for one version and switch them to another version. The code in D6 and D7 is totally different. Very few D6 solutions will work in D7. Very few problems are the same in both versions, even if the symptoms look the same. If you think you have a problem that doesn't already have a D7 issue, open a new issue for that, don't hyjack a D6 issue.
Comment #26
Striknin CreditAttribution: Striknin commentedOk, sorry ... I apologize.
I'm still not familiar with the issue system ...
I'll open a new issue for D7.
Comment #27
iaminawe CreditAttribution: iaminawe commentedWas a D7 issue ever opened for this? I am looking to do the same thing and cannot find a D7 version of this issue.
Comment #28
gbernier CreditAttribution: gbernier commentedSame here, would love to have something that works since Date Browser is still useless
Comment #29
jjjames CreditAttribution: jjjames commentedsubscribe
Comment #30
gingerfrog CreditAttribution: gingerfrog commentedFor those looking for the 7.x solution, thread is here http://drupal.org/node/1409120
Comment #31
jlscott CreditAttribution: jlscott commentedHi. If anyone is interested, I have a snippet that alters the format used for a pair (start - end) of exposed date filters (views 3.x) and allows flexible input. This is done by setting the filter property of the form element and by adding an element validate function that interprets the input before the main validation routines check it.
Fisrt the form alter bit:
Note the use of array_unshift to get my validation function to the start of the list if an element validation function is already specified.
Next the validation function:
The supplied input is processed through the function "date($format, strtotime($date))" which will make a quite good interpretation of any supplied input as a date/time value and re-format into the represetnation expected by the date module validation. It can interpret strings like "today", "now", and just time strings are expanded to include today's date.
This validation function will ensure that if only one of the start or end dates is supplied, the other (either "today" for the start, or "now" for the end) will be added, allowing for easier entry of time ranges for the current date.
Note that user supplied input is located in two different places in the $element array, and is in both the $form_sate['values'] and $form_state['input'] arrays (yuk!!!). All four places should be updated the same way.
Note the use of the last three characters of the element id to determine whether this is for the start or end date.
The date validation function will replace the "$form_state['values']['field_mydatefield_value'][$minmax]['date']" item with a "$form_state['values']['field_mydatefield_value'][$minmax]" value when it has validated the input, so the function only updates the original value if it exists. See below for a dump when the start has been validated, but not the end, date which has had the string "now" translated to an actual date/time.
Hope this helps someone.
Comment #32
jcarballo CreditAttribution: jcarballo as a volunteer and commentedIn the Date field settings below the Help text there are the More settings and values. Inside, you'll see Data entry section, choose the format the you need.
Comment #33
mlhyyl CreditAttribution: mlhyyl commentedHad the same issue. In my case it was a setting I had forgotten to remove. Steps are below:
-go to your view
-go to advanced tab
-click on BEF Settings under Exposed Form
-go to your filter (in my case it was the line: Display "date" (Filter label: "Date") exposed filter as)
-"Default select list" should be selected. I had switched it to "jQuery UI Datepicker"
Comment #34
Chetna_Negi CreditAttribution: Chetna_Negi as a volunteer commented#5 worked for me
Comment #35
ladybug_3777 CreditAttribution: ladybug_3777 commentedThis might be useful for some people that are using the "Select" exposed filter and notice that the order of the month day and year drop downs change. Apparently when filtering on a custom date field the Short Format dictates the order of those fields when they are exposed to users:
https://www.drupal.org/node/2467819
Comment #36
davidkp CreditAttribution: davidkp commentedThanks ladybug_3777 #35 Date short format is the answer!