I'm having a view using dates to sort out what nodes to show. The dates are possible to input via the exposed filters and overall it works fine. the problem I have though is that I want the users to have to specify start and end dates, thus I leave the Optional checkbox unchecked. Still, the output of the exposed filters contains options along the line of '-Year' and -Month' (shown like that WITH the Html code in Safari in the select list as well) which, when selected, results in all nodes being shown.
For the Taxonomy filter of the View I've checked and unchecked the Optional checkbox and the option is abled/disabled as it should there, so it seems to be a problem only with dates.
The View exported:
$view = new view;
$view->name = 'regionskarta';
$view->description = 'Hämtar alla noderna i det län som skickas som argument';
$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('fields', array(
'title' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'body' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => 'test',
'hide_empty' => 0,
'empty_zero' => 0,
'exclude' => 0,
'id' => 'body',
'table' => 'node_revisions',
'field' => 'body',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'aktivitet' => 'aktivitet',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
'override' => array(
'button' => 'Override',
),
),
'tid' => array(
'operator' => 'or',
'value' => array(),
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'tid_op',
'identifier' => 'tid',
'label' => 'Län:',
'optional' => 0,
'single' => 1,
'remember' => 1,
'reduce' => 0,
),
'type' => 'select',
'limit' => TRUE,
'vid' => '1',
'id' => 'tid',
'table' => 'term_node',
'field' => 'tid',
'hierarchy' => 0,
'relationship' => 'none',
'reduce_duplicates' => 0,
),
'tid_1' => array(
'operator' => 'or',
'value' => '',
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'tid_1_op',
'identifier' => 'tid_1',
'label' => 'Typ av aktivitet:',
'optional' => 1,
'single' => 0,
'remember' => 0,
),
'type' => 'textfield',
'limit' => TRUE,
'vid' => '2',
'id' => 'tid_1',
'table' => 'term_node',
'field' => 'tid',
'hierarchy' => 0,
'relationship' => 'none',
'reduce_duplicates' => 0,
),
'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' => 'Från:',
'optional' => 0,
'remember' => 0,
),
'date_fields' => array(
'node_data_field_date.field_date_value2' => 'node_data_field_date.field_date_value2',
),
'date_method' => 'AND',
'granularity' => 'day',
'form_type' => 'date_select',
'default_date' => 'now',
'default_to_date' => '',
'year_range' => '-0:+3',
'id' => 'date_filter',
'table' => 'node',
'field' => 'date_filter',
'relationship' => 'none',
),
'date_filter_1' => array(
'operator' => '<=',
'value' => array(
'value' => NULL,
'min' => NULL,
'max' => NULL,
'default_date' => 'now +7 day',
'default_to_date' => '',
),
'group' => '0',
'exposed' => TRUE,
'expose' => array(
'use_operator' => 0,
'operator' => 'date_filter_1_op',
'identifier' => 'date_filter_1',
'label' => 'Till:',
'optional' => 0,
'remember' => 0,
),
'date_fields' => array(
'node_data_field_date.field_date_value' => 'node_data_field_date.field_date_value',
),
'date_method' => 'AND',
'granularity' => 'day',
'form_type' => 'date_select',
'default_date' => 'now +7 day',
'default_to_date' => '',
'year_range' => '-0:+3',
'id' => 'date_filter_1',
'table' => 'node',
'field' => 'date_filter',
'relationship' => 'none',
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('use_more', 0);
$handler->override_option('distinct', 1);
$handler->override_option('style_plugin', 'gmap');
$handler->override_option('style_options', array(
'grouping' => '',
'macro' => '[gmap height=300px | width=100%]',
'datasource' => 'location',
'markers' => 'static',
'markertype' => 'alltforbarn marker',
));
$handler->override_option('row_options', array(
'inline' => array(),
'separator' => '',
'hide_empty' => 0,
));
$handler->override_option('exposed_block', TRUE);
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
$handler = $view->new_display('panel_pane', 'Gmap Panel', 'panel_pane_1');
$handler->override_option('fields', array(
'title' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
));
$handler->override_option('style_options', array(
'grouping' => '',
'macro' => '[gmap height=300px | width=100%]',
'datasource' => 'location',
'markers' => 'taxonomy',
'markertype' => 'alltforbarn marker',
));
$handler->override_option('pane_title', 'regionskarta-Gmap');
$handler->override_option('pane_description', '');
$handler->override_option('pane_category', array(
'name' => 'View panes',
'weight' => 0,
));
$handler->override_option('allow', array(
'use_pager' => FALSE,
'items_per_page' => FALSE,
'offset' => FALSE,
'link_to_view' => FALSE,
'more_link' => FALSE,
'path_override' => FALSE,
'title_override' => FALSE,
'exposed_form' => FALSE,
));
$handler->override_option('argument_input', array());
$handler->override_option('link_to_view', 0);
$handler->override_option('inherit_panels_path', 0);
$handler = $view->new_display('panel_pane', 'HTML-lista', 'panel_pane_2');
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'grouping' => '',
'type' => 'ul',
));
$handler->override_option('pane_title', 'regionskarta-html');
$handler->override_option('pane_description', '');
$handler->override_option('pane_category', array(
'name' => 'View panes',
'weight' => 0,
));
$handler->override_option('allow', array(
'use_pager' => FALSE,
'items_per_page' => FALSE,
'offset' => FALSE,
'link_to_view' => FALSE,
'more_link' => FALSE,
'path_override' => FALSE,
'title_override' => FALSE,
'exposed_form' => FALSE,
));
$handler->override_option('argument_input', array());
$handler->override_option('link_to_view', 0);
$handler->override_option('inherit_panels_path', 0);
Comment | File | Size | Author |
---|---|---|---|
#25 | 681450-25-views.php_.txt | 8.96 KB | jbylsma |
#15 | 681450.view_.txt | 3.06 KB | Bevan |
#8 | date-681450-2.patch | 1.41 KB | jbylsma |
#7 | date-681450.patch | 617 bytes | maijs |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedAS per the submission guidelines.
Comment #2
FreddieK CreditAttribution: FreddieK commentedThe problem seems to be that no matter if the date filters are set to 'optional' => 0, or 1 the result is the same, with the any option showing.
Oh, and what I meant is that in the Select list the string output is including the html tags, literally outputting them in the list.
Comment #3
FreddieK CreditAttribution: FreddieK commented(Sorry, was writing the last reply while you answered so accidently changed back the values)
Comment #4
FreddieK CreditAttribution: FreddieK commentedSo, this far I've found that I can solve my problem (not a nice solution though) in the function date_select_process() in date_api_elements.inc.
I can't find where the 'optional' variable from Views disappears to set it as $element['#required'] which would be the general solution to get the 'optional' checkbox to work.
Also, when $part_required is set to true, it should also change $element['#date_label_position'] from 'within' to 'none', otherwise the extra option will still be created (and given the name, if only $element['#date_label_position'] is changed an empty select option will still generate).
Comment #5
gunzip CreditAttribution: gunzip commentedI've the inverse problem for an exposed optional date filter. Even if i leave the defaults blank in the filter settings, no matter what, i still obtain a where clause ( = 2010-01-01 ...) that shouldn't be there. It looks like optional exposed date filter for view doesn't work (i've tried with both stable and dev version) at all...
Comment #6
chellman CreditAttribution: chellman commentedSubscribing. There's a more recent issue #717682: Views filter "optional" option not working? that seems to be a duplicate, but has some other, different code as well.
Comment #7
maijs CreditAttribution: maijs commentedchellman, I think it's not a duplicate of #717682: Views filter "optional" option not working? rather than a bug in Date API. I found that in date_api_elements.inc file, there is an uncommented line that makes all the difference with '#required' element in form array. With this fix, I don't get any (= 2010-01-01) statements in sql query if field it empty.
Patch is provided for 6.x-2.x-dev, will also do for 6.x-2.4.
Patch for date_api_elements.inc is quite simple (around line 154).
Comment #8
jbylsma CreditAttribution: jbylsma commentedThe patch appears to work as expected, but it appears that the view would still use a default value if the exposed filter wasn't set (the initial loading of a view). I added a check in the "includes/date_api_filter_handler.inc" file that will allow the view to not set a default value if the filter has been marked optional. The attached patch file includes maijs' patch from comment #7. I have checked this against 6.x.-2.4 but not against the dev branch.
In doing this, I realized that the filter isn't behaving correctly if the field is required. Filters that are optional are working just fine. I wrote out what I anticipated as the expected behaviors below:
I'm generally familiar with Views and the Date module, but if I'm missing something or this isn't what the default behavior should be, please let me know! Fixing the required field isn't a priority for me, but hopefully I might get some time in the future to address it.
Comment #9
YK85 CreditAttribution: YK85 commentedsubscribing
Comment #10
YK85 CreditAttribution: YK85 commentedIs this related to #856238: exposed filter of created date with "Is between" and optional returns empty results?
Comment #11
gunzip CreditAttribution: gunzip commentedthe patch works for me.
Comment #12
crea CreditAttribution: crea commentedSubscribing
Comment #13
Bevan CreditAttribution: Bevan commentedThe patch from comment #8 fixes the bug. It will take longer to test this more extensively, but here is more detail on how to reproduce the bug consistently. Unless otherwise specified, use default settings on all forms;
WHERE
clause.WHERE DATE_FORMAT(ADDTIME(STR_TO_DATE(node_data_field_date.field_date_value, '%Y-%m-%%dT%T'), SEC_TO_TIME(46800)), '%Y-%m-%%d') = '2010-01-01'
. Note especially the presence of "2010-01-01
", which is seemingly being generated from nowhere.Comment #14
Bevan CreditAttribution: Bevan commentedyaz086; #856238: exposed filter of created date with "Is between" and optional returns empty results is about date filters for node dates that are supported in views, while this ticket is about CCK Date fields, supported by date module. Though the bugs are very similar, the causes and fixes are entirely unrelated.
Comment #15
Bevan CreditAttribution: Bevan commentedThe attached view for Views 3 is what results from the steps in comment #13.
Comment #16
KarenS CreditAttribution: KarenS commentedThis is a lovely report with lots of details. I can replicate the problem but the patch does not fix it. And I'm not sure I agree with the idea of what *should* happen anyway.
If a field is required and empty I think the query should return nothing until the filter is populated. It makes no sense to me to force a required filter to be as generous as possible (i.e. show everything) until it is populated. It should show nothing.
The default behavior of 2010-01-01 is totally wrong of course, I'm still digging around to figure out where that is getting set.
Comment #17
Bevan CreditAttribution: Bevan commentedI assume you mean "filter" instead of "field"?
The filter is not required. It is optional. As per "Expected behaviour" in comment #13, the default for Views filters (at least in Views 3) is for "Optional" to be checked.
What do you mean by "the patch does not fix it"? If you unchecked "Optional", then the patch might not make a difference to the actual behaviour (needs testing). Of course your expected behaviour will probably be different to comment #13! (:
Comment #2 on #717682 (Closed - Duplicate) has an explanation that maybe useful;
Comment #18
TommyK CreditAttribution: TommyK commentedWould the same underlying problem here be the same reason that I cannot get Date Arguments to work when I have an optional To field?
I can create a date field that has either a To field Never or Required and the View works with Year granularity as an argument, but if the field has an optional To field the View returns nothing. This is when I am using From date as the source for the argument, so it doesn't quite make sense that the To field would matter.
I can create a new issue with steps to reproduce if it would not be a duplicate.
Comment #19
Bevan CreditAttribution: Bevan commentedTommyK; That is probably not the same problem and sounds like a different bug. Please look for another issue with the same symptoms as yours, or create a new issue node with the most steps possible on how to reproduce the bug.
Comment #20
gagarine CreditAttribution: gagarine commentedI think comment in #16 is a misunderstood of the problem see #17.
Comment #21
brunorios1 CreditAttribution: brunorios1 commentedI agree with KarenS in #16...
I'm having the same problem.
I have a Map with events, and i need to "force" the users to choose a Date (day granularity)...
But even unchecking "optional", the view don't require a date and if i leave empty, it shows all the events of the site in the map...
Comment #22
Agileware CreditAttribution: Agileware commentedSubscribing
Patch in #8 works here for both required and optional cases
Comment #23
arlinsandbulte CreditAttribution: arlinsandbulte commentedPutting on my list to review and commit...
Comment #24
arlinsandbulte CreditAttribution: arlinsandbulte commentedIn my testing, this patch is not needed.
Without the patch:
Creating an exposed filter with select list format & all default values blank, all nodes are displayed by default (nothing is filtered out).
Selecting a date in the exposed filter does properly apply that filter.
With the patch (had to re-roll it as it did not apply an more):
The above behavior was unchanged.
NOTE:
If the exposed filter values are only partially filled out, for instance leaving one or more of the date elements empty, all values are returned. This may not be the desired behavior.
If anything here needs work it is that.
Comment #25
jbylsma CreditAttribution: jbylsma commentedI tested the following against Views 6.x-2.16 and Date 6.x-2.x-dev (two commits after 6.x-2.9).
I extended Drupal's provided "Page" content type with a Date CCK field and generated 50 "Page" nodes using devel generate. The generated dates range from 2009 to 2015.
I configured four Views with the following:
(Ahem, no thanks to Google Docs Spreadsheet "Download As" HTML. That outputted an HTML nightmare and required a near-complete reformat)
I expected the following behavior for the Views Date filters' fields "Date default" and "To date default" values
Looking at the data, it appears that all expected exposed filter settings are incorrect and only the Text/Required view is displaying the correct initial values. In addition, the two required fields are both allowing exposed filters to be bypassed.
I rerolled the patch I posted in #681450-8: Views optional exposed date filter does not work without value but it appears that it breaks current functionality and doesn't fix any current issues. When I had originally posted the patch, I was looking to create an optional Date exposed filter textbox that showed all values by default but allowed users to enter a specific year to narrow results. I believe my original issue what that, even though my exposed filter was optional, the result set was automatically filtered to the generated default value. That was quite a while ago and I can't easily test if that's the case anymore.
I've attached the Views I created to generate all of the data. Hopefully this will at least illuminate the issues at hand.
Comment #26
jbylsma CreditAttribution: jbylsma commentedOne day I will remember to update the issue settings before I post...
Comment #27
Bevan CreditAttribution: Bevan commentedThank you for the fantastically detailed testing and report. It looks like this patch needs more work then?
Comment #28
DamienMcKennaUnfortunately the D6 version of this module is no longer supported, but we appreciate the time you put into this. If this problem is relevant for D7 too, please reopen the issue. Thanks.