2

I have an AJAX view using Views 3 and Better Exposed Filters (and therefore jQuery UI datepicker). One of the exposed filters is dates between [post-date] (core).

The form works fine, but when dates are entered and submitted (via AJAX) the visible entries in the input fields disappear.

Before:

before submit

After:

after sumbit

It doesn't happen to other text fields, only date fields, and it stops happening when I change the Exposed Form type to 'Basic'. I'm sure it's BEF causing the issue but what's really puzzling is that the input values are there in the HTML after submit:

<input ... value="2015-05-01" ...>

Why isn't it showing in the input field?

[edit:] I tried to reproduce this on a blank site and couldn't. No longer certain the root cause is in BEF.


Additional information:

I've tracked the problem down to some custom JQuery code to add options to the datepicker post-render. The options are added no worries, I just can't figure out why it breaks the inputs.

(function ($) {
Drupal.behaviors.myPageFilters = {
  attach: function (context, settings) {

    $("label[for='edit-post-date-max']", context).once('changeBetweenText', function(){
        $(this).text("to");
    });


    // This is the culprit, commenting out this block stops the weird behaviour
    $(".bef-datepicker", context).once('changeDatePickerFormat', function(){
        $(this).datepicker("option", "changeYear", true).datepicker("option", "changeMonth", true);
        $(this).datepicker("option", "dateFormat", "yy-mm-dd").datepicker("option", "showButtonPanel", true);
        $(this).datepicker("option", "buttonImage", "/sites/all/themes/mytheme/images/exposed-filter-calendar.png").datepicker("option", "showOn", "both");
    });



    $(".bef-secondary-options", context).once('createSecondarySubmit', function(){
        $(this).append('<input type="submit" id="bef-secondary-submit" value="Apply" class="form-submit">');
    });

  }
};   
}(jQuery));

It's this:

$(this).datepicker("option", "dateFormat", "yy-mm-dd");

I placed it there to change the date format away from the US format provided in BEF code (AUS site).

I just discovered the jQuery UI Datepicker option field in BEF. /facepalm

I'll leave this question here in case anyone ends up with the same issue.

1 Answer 1

0

Put your datepicker options in via the Views UI rather than custom jQuery.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.