Posted by Tharya on June 26, 2009 at 8:59am
29 followers
Jump to:
| Project: | Date |
| Version: | 6.x-2.x-dev |
| Component: | Date Popup |
| Category: | support request |
| Priority: | normal |
| Assigned: | enboig |
| Status: | closed (fixed) |
Issue Summary
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
#1
That'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
#2
The link above actually did work - it's a hack though :(
#3
I 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?
#4
also interested in doing this a clean way!
#5
What 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.
<?php
/**
* Implementation of hook_form_alter().
*/
function mymodule_form_views_exposed_form_alter(&$form, &$form_state) {
if($form['#id'] == 'your-exposed-formid') {
$form['date_filter_1']['min']['#date_format'] = 'm-d-Y';
$form['date_filter_1']['max']['#date_format'] = 'm-d-Y';
}
}
?>
#6
subscribing
#7
#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!
#8
ok, maybe not that loud, sorry
#9
I 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
#10
I 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:
function mymodule_form_views_exposed_form_alter(&$form, &$form_state) {
if($form['#id'] == 'views-exposed-form-events-all-search-panel-pane-1') {
$form['date_filter_1']['min']['#date_format'] = 'm-d-Y';
$form['date_filter_1']['max']['#date_format'] = 'm-d-Y';
}
}
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
#11
Maxim75
I have placed code from above in general form_alter handler (i.e. in mymodule_form_alter) and everything works fine. Code looks like
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id){
...
if($form_id == 'views_exposed_form'){
if($form['#id'] == 'views-exposed-form-events-all-search-panel-pane-1'){
$format = 'm-d-Y';
$form['date_filter']['min']['#date_format'] = $format;
$form['date_filter']['max']['#date_format'] = $format;
}
...
}
?>
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.
#12
Thanks 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
#13
#14
Automatically closed -- issue fixed for 2 weeks with no activity.
#15
I 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
#16
I 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....
<?phpfunction date_popup_form_views_ui_config_item_form_alter(&$form, $form_state) {
if ('2' != substr(views_api_version(), 0, 1)) {
// Only continue for Views 2.x
return;
}
if (!empty($form['options']['expose'])) {
if (isset($form['options']['value']['type']['#options']) && array_key_exists('date', $form['options']['value']['type']['#options'])) {
$form['options']['value']['type']['#options']['user_defined_date'] = t('A user defined date using PHP date() wildcards');
$form['options']['value']['date_format'] = array(
'#type' => 'textfield',
'#title' => t('Date_format'),
'#default_value' => !empty($form_state['handler']->options['value']['date_format']) ? $form_state['handler']->options['value']['date_format'] : 'Y/m/d',
);
}
}
}
function date_popup_form_views_exposed_form_alter(&$form, $form_state) {
foreach ($form_state['view']->filter as $field => $filter) {
if ($filter->options['value']['type']=='user_defined_date') {
switch($filter->options['operator']) {
case 'between':
$form[$filter->options['id']]['min']['#type'] = 'date_popup';
$form[$filter->options['id']]['min']['#size'] = '20'; //YYYY-MM-DD HH:MM:SS
$form[$filter->options['id']]['min']['#date_format'] = $filter->options['value']['date_format'];
$form[$filter->options['id']]['max']['#type'] = 'date_popup';
$form[$filter->options['id']]['max']['#size'] = '20'; //YYYY-MM-DD HH:MM:SS
$form[$filter->options['id']]['max']['#date_format'] = $filter->options['value']['date_format'];
break;
default:
$form[$filter->options['id']]['#type'] = 'date_popup';
$form[$filter->options['id']]['#size'] = '20'; //YYYY-MM-DD HH:MM:SS
$form[$filter->options['id']]['#date_format'] = $filter->options['value']['date_format'];
break;
}
}
}
}
?>
#17
I've updated the snippet above for views 3.x
<?php
function mymodule_form_alter(&$form, &$form_state, $form_id){
...
if($form_id == 'views_exposed_form'){
if($form['#id'] == 'views-exposed-form-events-all-search-panel-pane-1'){
$format = 'm-d-Y';
$form['date_filter']['value']['#date_format'] = $format;
}
...
}
?>
#18
subscribe
#19
enboig, thank for your code.
it helped me with some revisions:
<?php
function MYMODULE_form_views_ui_config_item_form_alter(&$form, $form_state) {
if ('2' != substr(views_api_version(), 0, 1)) {
// Only continue for Views 2.x
return;
}
if (!empty($form['options']['expose'])) {
$form['options']['value']['type']['#options']['user_defined_date'] = t('A user defined date using PHP date() wildcards');
$form['options']['value']['date_format'] = array(
'#type' => 'textfield',
'#title' => t('Date_format'),
'#default_value' => !empty($form_state['handler']->options['value']['date_format']) ? $form_state['handler']->options['value']['date_format'] : 'Y/m/d',
);
}
}
function MYMODULE_form_views_exposed_form_alter(&$form, $form_state) {
foreach ($form_state['view']->filter as $field => $filter) {
if ($filter->options['value']['date_format']) {
$el_id = $filter->options['id'];
if ($filter->options['expose']['identifier']) {
$el_id = $filter->options['expose']['identifier'];
}
switch($filter->options['operator']) {
case 'between':
$form[$el_id]['min']['#date_format'] = $filter->options['value']['date_format'];
$form[$el_id]['max']['#date_format'] = $filter->options['value']['date_format'];
break;
default:
$form[$el_id]['#date_format'] = $filter->options['value']['date_format'];
break;
}
}
}
}
?>
#20
I 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!
#21
Insert 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"
<?php
// $Id$
/**
* @file
* This is my custom module to change to date format to d-m-Y in exposed views filters
*/
function mymodule_form_alter(&$form, &$form_state, $form_id){
if($form_id == 'views_exposed_form'){
if($form['#id'] == 'views-exposed-form-order-panel-page'){
$format = 'd-m-Y';
$form['date_filter']['value']['#date_format'] = $format;
}
}
}
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.
#22
Thank 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!
#23
Subscribe - Thank you very much guys solution 16 was the easy fix.
#24
Hi,
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
<?phpfunction 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
#25
Please 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.
#26
Ok, sorry ... I apologize.
I'm still not familiar with the issue system ...
I'll open a new issue for D7.
#27
Was a D7 issue ever opened for this? I am looking to do the same thing and cannot find a D7 version of this issue.
#28
Same here, would love to have something that works since Date Browser is still useless
#29
subscribe
#30
For those looking for the 7.x solution, thread is here http://drupal.org/node/1409120