Hi, everyone. I have two date fields, how to create only one date exposed filter for two this field. I tried "Global:Combine field filter" and views filter populate but can't not resolve this problem. Thanks.

Comments

Iceabenezer’s picture

Same issue here. I have to have two different date fields because I have to collect different granularity depending on the product selected. Any thoughts?

morrisem’s picture

After struggling with this same issue, I "solved" it by creating two exposed date filters with Filter identifiers "f1" and "f2", hiding f2 via CSS, and then using the Javscript injector module to inject the following jQuery into the page with the exposed filters:

var $f1 = jQuery("input#edit-field-f1-value-datepicker-popup-0");
var $f2 = jQuery("input#edit-field-f2-value-datepicker-popup-0");

$f1.change(function()
{
   $f2.val($f1.val());
});

Thus, whenever f1 is changed, f2 is set to its value, so both filters test against the same thing, but only one field is presented to the user. A bit hackish, but it's the best I could figure out.

P2790’s picture

@morrisem
I have been trying your code, but it just doesn't seem to work. Nothing seems to happen
Are your exposed filters using the date popup

P2790’s picture

I used:

(function ($) {

$(function () {
    $("#edit-f1-min-datepicker-popup-0, #edit-f2-min-datepicker-popup-0, #edit-f3-min-datepicker-popup-0").datepicker();
    $("#edit-f1-min-datepicker-popup-0").datepicker("option", "onSelect", function (dateText, inst) {
        var date1 = $.datepicker.parseDate(inst.settings.dateFormat || $.datepicker._defaults.dateFormat, dateText, inst.settings);

      	var date2 = new Date(date1.getTime());
        date2.setDate(date2.getDate() + 1);
        $("#edit-f2-min-datepicker-popup-0").datepicker("setDate", date2);

      	var date3 = new Date(date1.getTime());
        date3.setDate(date3.getDate() + 2);
        $("#edit-f3-min-datepicker-popup-0").datepicker("setDate", date3);

    });
});

}(jQuery));

Also using the preprocess and the header in js injector

jincy_k’s picture

I also have a similar requirement. In views exposed filter, I need to show a start date and a select field for showing the number of weeks. User on selecting the start date(pop up field) and number of weeks, I want to calculate and populate the end date field. In hook_views_query_alter, I'm trying to alter the conditions. But no luck for date filter. Please help me with a reply. Please correct me if I'm doing something wrong.

DamienMcKenna’s picture

Version: 7.x-2.8 » 7.x-2.x-dev
Assigned: tuanhcmup » Unassigned

As a reminder, the "assigned" field is for indicating that you're actively working on something.