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.
Hello,
I don't now how can I do this. I'm 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
function date_fixed_format_form_alter(&$form, &$form_state, $form_id){
if($form_id == 'views_exposed_form'){
if ($form['#id'] == 'views-exposed-form-liste-des-offres-page-1') {
$form['date_filter']['value']['#date_format'] = 'd-m-Y';
}
}
}
Someone can say me how to format my exposed filters with date popup ?
Thanks
Comment | File | Size | Author |
---|---|---|---|
#24 | GF.png | 54.71 KB | pachai.drupal |
#17 | date-exposed_filter_format-1409120-17.patch | 2.76 KB | MustangGB |
#5 | date_exposed_filter_format-1409120-5.patch | 1.82 KB | anrikun |
#4 | screenshot-date_as_field_respects_configured_format.jpg | 20.08 KB | anrikun |
#4 | screenshot-date_as_exposed_filter_ignores_configured_format.jpg | 7.56 KB | anrikun |
Comments
Comment #1
Wario CreditAttribution: Wario commentedSubscribe.
Comment #2
anrikun CreditAttribution: anrikun commentedThis is a bug and a major one as it is a regression: AFAIK this used to work as expected in D6.
Comment #3
Pomliane CreditAttribution: Pomliane commented@anrikun: I don't think so. See: #502824: Date format in exposed filter (views) cited by marsbidon.
If not a duplicate, this issue should probably be a Feature request, not a bug and the title should be changed.
Comment #4
anrikun CreditAttribution: anrikun commentedYou are right, I made a confusion between date exposed filter and date field.
Anyway, I still think this is a bug, because there is no consistency between date field that respects configured "short" format and date exposed filter that ignores it.
See attached screenshots:
- field uses the French short format as configured
- but exposed filter ignores it and uses the default English format
Don't you think that field and exposed filter should behave the same?
Edit: I just wonder, should this be addressed in Date or in Views?
Comment #5
anrikun CreditAttribution: anrikun commentedA first try.
Comment #6
KarenS CreditAttribution: KarenS commentedThere are numerous problems here. First, there is nothing more magical about using the site-wide short format than what is being used. That still might or might not be what is desired.
Second, the format will vary depending on the granularity of the filter. Using a format designed for some other purpose won't necessarily make any sense when used with a different granularity.
Third, this value is used to filter the view, which is why it is use the sql format. If you don't use that format we have to add code to transform a value in some other format into the sql format that is needed by the query.
So making this change is more complex that this patch would imply.
This is not a bug, it is a feature request. It works fine, you just don't like the way it looks.
Comment #7
Merkator CreditAttribution: Merkator commented@marsbidon, #21 works fine for me.
Here is my code. You have to correctly set xxxxxxxxxx and maybe changed "date_popup" with the type of date widget you use.
Comment #8
GuyB CreditAttribution: GuyB commentedLet me begin by saying what a great module this is, and offering my appreciation to the contributors.
I understand and appreciate the points made in #6, but I would like to echo the desire for more flexible formatting in the exposed filter. If it were feasible to allow the user to pick any of the standard date types for the filter, including any custom date formats, I think it would significantly enhance the usability of this module. Granted, the user would be responsible for making sure that the format chosen is consistent with the granularity.
In my case, I was trying to use the date field to store a time in days, hours, minutes. I wanted to filter and sort numerically on this field, while offering the customer a sensible display format of j:H:i. When using this format for input, the default year and month stored is 0000 and 01, which works fine for my purposes. The only trouble I get into is when the customer tries to filter on the field, and is confronted with the confusing long date format.
I imagine there are similar use cases that would benefit from being able to choose the format.
Comment #9
modctek CreditAttribution: modctek commentedSubscribing, though it sounds like maybe this will end up as a "Won't fix"?
Comment #10
drasgardian CreditAttribution: drasgardian commentedI would also like to see better flexibility of date input formats here.
The workaround from #7 can get the input format correct, but will break any CSV view displays attached as the other displays don't know to try and transform the date back into a the sql compatible format.
Comment #11
jh81 CreditAttribution: jh81 commentedI also would like to make this feature request. Its confusing to end users to see a date formatted one way in the view which is configurable and see the date formatted a completely different way on an exposed date filter. This fix would be either match what is formatted in the view or allow the exposed date field filter to have a date format option.
Comment #12
donpwinston CreditAttribution: donpwinston commentedIt's mind boggling that someone did not see fit to fix this problem. There is also a "problem" with times. It does not support time all by itself with no date. Also the display of date fields in data entry forms is ridiculous. They try to pack too many features into one widget. What's with the start and end feature? I've used date "widgets" from everything to SAS to Smalltalk. No one does that.
Date popup supports changing the date format in a node add/edit form. Why not in an exposed form of a view? It makes no sense. From someone else's post the reason is because it's a little more difficult to do. Ditto for a stand alone time field.
Looks like I'll have to resort to adding some javascript to the page of the form to set the format. This is cruddy.
Comment #13
donpwinston CreditAttribution: donpwinston commentedI take some of this back. I was able to set the appropriate format using
Better then adding js to the page but you should be able to do this in the admin UI.
Comment #14
hwasem CreditAttribution: hwasem commentedThank you for this, donpwinston. It worked well for me, although I did have to do some re-jiggering with Better Exposed Filters and their date-picker piece.
Comment #15
acbramley CreditAttribution: acbramley commented+1 for this feature, I think it would make sense to have the ability to set a format in the views ui with the rest of the settings for the exposed filter. Even if this was a display only change (maybe a form_alter in the date module itself using the provided format?)
Comment #16
acbramley CreditAttribution: acbramley commentedAlso, the form_alter solutions mentioned above don't seem to work for the node updated date exposed filters
Comment #17
MustangGB CreditAttribution: MustangGB commentedI think VivienLetang almost got it right over at #1647386: Wrong date format displaying in date popup field in an exposed views filter form
See attached patch.
Comment #18
MustangGB CreditAttribution: MustangGB commentedComment #19
Yusuf.Fidan CreditAttribution: Yusuf.Fidan commentedpatch works fine for me.
Comment #20
Countach CreditAttribution: Countach commented#17 works for me too.
Comment #21
weri CreditAttribution: weri commentedPatch #17 works fine. Please apply the patch to the next release.
Comment #22
anrikun CreditAttribution: anrikun commentedIf this works fine, it should be RTBC :-)
Comment #23
Pablo Gancharov CreditAttribution: Pablo Gancharov commentedthis worked perfectly in my drupal 7.16
Thanks!
Comment #24
pachai.drupal CreditAttribution: pachai.drupal commentedIs there any way to add an extra field in the Filter Granularity like filtering only by Date & Month. In my scenario i need to filter the date of birth in view by only Date and Month only, i don't want the year field to displayed and used in the query. But as of now we have year filter in each and every query executing, is there any patch available.
Please find the attachment for your reference.
Comment #25
Sol Roth CreditAttribution: Sol Roth commented#17 The dates are not "remembered" in the correct format when you check remember on exposed date views filters.
Comment #26
edvanleeuwenWhen is this incorporated in the dev-version? I see that this is tested and verified a couple of months ago.
Comment #27
jonathan1055 CreditAttribution: jonathan1055 commentedThe issue #1855810: Define #return_value_format for date_popup to set the form value is similar. Not sure if exactly the same problem though.
Comment #28
cafuego CreditAttribution: cafuego commentedApplied to 7.x-2.x.
Comment #30
vivdrupal CreditAttribution: vivdrupal commentedWith Field collections date field my solution was :
$form['field_work_preference_field_available_to_start']['#date_format'] = 'd/m/Y';
Comment #31
hughworm CreditAttribution: hughworm as a volunteer commentedThere is a problem with patch #17 if the "short" date format doesn't contain the year.
I have a "short" format of "D d M", which serves my purposes fine except that the view_formats() method of date_sql_handler assumes it contains the year, and as a result views exposed filters show day and month only (might have been useful for pachai.drupal in #24!).
To work around it I've reset "short" format to default and added a new "short-no-year" format to use.
Is this a dependency that can be removed?