This was initially reported in #367970: Exposed filter with Date field doesn't work.
I have created a view using an exposed date filter. I am only using a year's granularity in the filter (ie my view will list all the nodes that have a particular year in the date field).
The filter does not appear to run at all the first time when the view is called. When the view is called, the filter is displayed, showing the current year (2009, which was set as the default), but there are no nodes displayed. When you subsequently click on the "apply" button, then you get a list of 2009 nodes.
It looks to me as though the initial query is wrong - if I look at the views preview, the query shows the year as being '0009' instead of '2009'. As a test, I created a node with a year of 0009, and voila! this node gets displayed when the view first runs.
The filter however, shows "2009" as the entry in the form on the exposed filter. This is what threw me initially - it looked as though the view was not running when it was first called. It was, but because I didn't happen to have have any '0009' nodes in the system at that time, the view came up empty.
I have attached a screen shot of the query when shown in views preview - this clearly shows the date as being '0009'.
In live preview, if I then click on the "apply" button, the query correctly shows '2009' and I get a list of 2009 nodes.
Here's an export of the CCK type that I am using:
$content['type'] = array (
'name' => 'testevent',
'type' => 'testevent',
'description' => 'A content type for testing the date module and exposed filters',
'title_label' => 'Title',
'body_label' => 'Body',
'min_word_count' => '0',
'help' => '',
'node_options' =>
array (
'status' => true,
'promote' => false,
'sticky' => false,
'revision' => false,
),
'old_type' => 'testevent',
'orig_type' => '',
'module' => 'node',
'custom' => '1',
'modified' => '1',
'locked' => '0',
'comment' => '0',
'comment_default_mode' => '4',
'comment_default_order' => '1',
'comment_default_per_page' => '50',
'comment_controls' => '3',
'comment_anonymous' => 0,
'comment_subject_field' => '1',
'comment_preview' => '1',
'comment_form_location' => '0',
);
$content['fields'] = array (
0 =>
array (
'label' => 'eventdate',
'field_name' => 'field_eventdate',
'type' => 'date',
'widget_type' => 'date_select',
'change' => 'Change basic information',
'weight' => '-3',
'default_value' => 'now',
'default_value2' => 'same',
'default_value_code' => '',
'default_value_code2' => '',
'input_format' => 'Y-m-d H:i:s',
'input_format_custom' => '',
'year_range' => '-3:+3',
'increment' => '1',
'advanced' =>
array (
'label_position' => 'above',
'text_parts' =>
array (
'year' => 0,
'month' => 0,
'day' => 0,
'hour' => 0,
'minute' => 0,
'second' => 0,
),
),
'label_position' => 'above',
'text_parts' =>
array (
),
'description' => '',
'group' => false,
'required' => 1,
'multiple' => '0',
'repeat' => 0,
'todate' => '',
'granularity' =>
array (
'year' => 'year',
'month' => 'month',
'day' => 'day',
),
'default_format' => 'medium',
'tz_handling' => 'none',
'timezone_db' => '',
'op' => 'Save field settings',
'module' => 'date',
'widget_module' => 'date',
'columns' =>
array (
'value' =>
array (
'type' => 'varchar',
'length' => 20,
'not null' => false,
'sortable' => true,
'views' => true,
),
),
'display_settings' =>
array (
'label' =>
array (
'format' => 'above',
'exclude' => 0,
),
'teaser' =>
array (
'format' => 'default',
'exclude' => 0,
),
'full' =>
array (
'format' => 'default',
'exclude' => 0,
),
4 =>
array (
'format' => 'default',
'exclude' => 0,
),
),
),
);
$content['extra'] = array (
'title' => '-5',
'body_field' => '-2',
'menu' => '-4',
);
And here is an export of the view that I am currently using:
$view = new view;
$view->name = 'eventview';
$view->description = 'eventview';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'testevent' => 'testevent',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'date_filter' => array(
'operator' => '=',
'value' => array(
'min' => '',
'max' => '',
'value' => '',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'date_fields' => array(
'node_data_field_eventdate.field_eventdate_value' => 'node_data_field_eventdate.field_eventdate_value',
),
'date_method' => 'OR',
'granularity' => 'year',
'form_type' => 'date_select',
'default_date' => '',
'default_to_date' => '',
'year_range' => '-3:+3',
'id' => 'date_filter',
'table' => 'node',
'field' => 'date_filter',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('row_plugin', 'node');
$handler->override_option('row_options', array(
'teaser' => 1,
'links' => 1,
'comments' => 0,
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'testevent' => 'testevent',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'date_filter' => array(
'operator' => '=',
'value' => array(
'value' => NULL,
'min' => NULL,
'max' => NULL,
'default_date' => 'now',
'default_to_date' => '',
),
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'date_filter_op',
'identifier' => 'date_filter',
'label' => 'Date: Date',
'optional' => 0,
'remember' => 0,
),
'date_fields' => array(
'node_data_field_eventdate.field_eventdate_value' => 'node_data_field_eventdate.field_eventdate_value',
),
'date_method' => 'OR',
'granularity' => 'year',
'form_type' => 'date_select',
'default_date' => 'now',
'default_to_date' => '',
'year_range' => '-3:+3',
'id' => 'date_filter',
'table' => 'node',
'field' => 'date_filter',
'override' => array(
'button' => 'Use default',
),
'relationship' => 'none',
),
));
$handler->override_option('path', 'eventlist');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
));
This was tested on a D6.10 install, with the latest dev versions:
CCK: 6.x-2.2
Views: 6.x-2.3
Date: 6.x-2.x-dev 2009-Mar-21
It looks to me as though the filter is correct, but the initial query is wrong.
I hope this helps.
| Comment | File | Size | Author |
|---|---|---|---|
| date-query.jpg | 44.09 KB | petey318 |
Comments
Comment #1
petey318 commentedI tested just now, against 6.x-2.x-dev 2009-Mar-25 and I still get the same result. This looks similar to the problem reported in #406256: Default parameter for exposed filter uses malformed date in SQL query however for my testing, I am using a fresh D6.10 install, and the only modules in use are CCK, Views, and Date.
Comment #2
karens commentedOK, I can replicate the problem, but only if the exposed filter is using the 'select' widget. It works fine with either the text or Date popup widgets, so it's something specific to that particular widget.
Comment #3
karens commentedClarifying the issue.
Comment #4
karens commentedI think I've got this straightened out. It all comes about because Views treats exposed widgets that have never been submitted as though they were submitted, which was bypassing my insertion of the right default values.
Comment #5
Torenware commentedThe fix of this issue appears to have broken the date filter (see http://drupal.org/node/413790).
It also appears that the convert_tz call is getting done backwards.
Comment #6
karens commented#5, you reported all of this in #413790 and I responded there, so this comment is a duplicate.
Comment #7
petey318 commentedHi KarenS -
I confirm from my testing that this particular issue is fixed in 2.1 (and stayed fixed in the latest dev release, which is even better :) )
Sincere thanks,
Pete
Comment #8
karens commentedThanks for the confirmation.