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.

animare’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

animare’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