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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wario’s picture

Subscribe.

anrikun’s picture

Title: Specify date format in exposed filter (views) » Regression: date format in views exposed filter is wrong
Component: Date Popup » Views Filter
Category: task » bug
Priority: Normal » Major

This is a bug and a major one as it is a regression: AFAIK this used to work as expected in D6.

Pomliane’s picture

@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.

anrikun’s picture

Title: Regression: date format in views exposed filter is wrong » Date format in views exposed filter does not respect configured format
FileSize
7.56 KB
20.08 KB

You 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?

anrikun’s picture

Status: Active » Needs review
FileSize
1.82 KB

A first try.

KarenS’s picture

Category: bug » feature
Priority: Major » Normal
Status: Needs review » Needs work

There 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.

Merkator’s picture

@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.

function xxxxxxxxxx_form_alter(&$form, &$form_state, $form_id) {
    if($form["#id"] == "views-exposed-form-xxxxxxxxxxx"){
        $info = $form["#info"];
        foreach ($info as $filter) {
            $value = $filter['value'];
            if($form[$value]['value']['#type'] == "date_popup")
            {
                $format = 'd/m/Y';
                $form[$value]['value']['#date_format'] = $format;
            }
        }
    }
}
GuyB’s picture

Let 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.

modctek’s picture

Subscribing, though it sounds like maybe this will end up as a "Won't fix"?

drasgardian’s picture

I 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.

jh81’s picture

I 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.

donpwinston’s picture

It'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.

donpwinston’s picture

I take some of this back. I was able to set the appropriate format using

function tw_form_views_exposed_form_alter(&$form, $form_state) {
	$form['field_opening_date_value']['value']['#date_format'] = 'm/d/Y';
	$form['field_closing_date_value']['value']['#date_format'] = 'm/d/Y';
}

Better then adding js to the page but you should be able to do this in the admin UI.

hwasem’s picture

Thank 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.

acbramley’s picture

+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?)

acbramley’s picture

Also, the form_alter solutions mentioned above don't seem to work for the node updated date exposed filters

MustangGB’s picture

MustangGB’s picture

Status: Needs work » Needs review
Yusuf.Fidan’s picture

patch works fine for me.

Countach’s picture

#17 works for me too.

weri’s picture

Patch #17 works fine. Please apply the patch to the next release.

anrikun’s picture

Status: Needs review » Reviewed & tested by the community

If this works fine, it should be RTBC :-)

Pablo Gancharov’s picture

this worked perfectly in my drupal 7.16
Thanks!

pachai.drupal’s picture

FileSize
54.71 KB

Is 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.

Sol Roth’s picture

#17 The dates are not "remembered" in the correct format when you check remember on exposed date views filters.

edvanleeuwen’s picture

When is this incorporated in the dev-version? I see that this is tested and verified a couple of months ago.

jonathan1055’s picture

The issue #1855810: Define #return_value_format for date_popup to set the form value is similar. Not sure if exactly the same problem though.

cafuego’s picture

Status: Reviewed & tested by the community » Fixed

Applied to 7.x-2.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

vivdrupal’s picture

With Field collections date field my solution was :

$form['field_work_preference_field_available_to_start']['#date_format'] = 'd/m/Y';

hughworm’s picture

Issue summary: View changes

There 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?