When I have enabled AJAX and automatic submission for my view with a Better Exposed Filter I am getting the following JS Error when submitting the form. (I also don't have a datepicker anywhere within my form.)

Uncaught TypeError: Cannot read property 'dateformat' of undefined

Which I found was being caused by line 94 in better_exposed_filters.js by

typeof Drupal.settings.better_exposed_filters.datepicker_options.dateformat !== 'undefined') {

as datepicker_options was undefined so I added a check into the code before this line to fix the above issue. I then started getting the below Error.

Uncaught TypeError: Cannot read property 'length' of undefined

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tisteegz’s picture

I have made a patch adding my checks into the code which seems to remove the js errors.

tisteegz’s picture

Issue summary: View changes
mariancalinro’s picture

FileSize
1.57 KB

The underlying issue is that the settings are added more than once sometimes, because the method exposed_form_alter of the plugin better_exposed_filters_exposed_form_plugin is called more than once (probably multiple filters that use this bef plugin).

If the same property is added more than once, drupal_add_js will create an array of values. So instead of false, Drupal.settings.better_exposed_filters.datepicker will contain an array with two or more false values. Testing this property will be pass, as a non empty array, and the error will come from trying to access the dateformat property of the undefined variable Drupal.settings.better_exposed_filters.datepicker_options. See the code below:

      // Check for and initialize datepickers
      if (Drupal.settings.better_exposed_filters.datepicker &&
        // This setting is undefined when "bef_datepicker" setting is array of
        // false values and as a result "ui.datepicker" library does not get
        // included.
        typeof Drupal.settings.better_exposed_filters.datepicker_options.dateformat !== 'undefined') {

A quick fix would be to test if the properties are arrays, and to reduce them to a single value using the "or" operator.

The implementation of the quick fix is in the patch attached.

alexweber’s picture

This patch almost solves pretty much the same issue I'm experiencing except with the slider; js settings aren't getting saved because other processing for other filters in the same request overrides them.

The patch fixes half of it and does a nice merge of the results but there's still issues with the boolean "slider" and "datepicker" options because if there's another filter with no settings processed afterwards the flags get set back to false.

alexweber’s picture

I managed to get around that by making $bef_add_js default to FALSE on line 584 of better_exposed_filters_exposed_form_plugin.inc.

That prevents empty js settings from being added, it won't, however, prevent either one of datepicker or slider breaking if both are on the same page.

TravisJohnston’s picture

Hey mariancalinro,

Thanks for the patch, though I tried it and I am still getting the error. I am not having trouble with my filters though. I have been experiencing the issue when I try to use VBO in a Rules Component. When I choose the option to load objects via vbo, the toggle spins then nothing happens and in the console log it says that dateformat is undefined.

Ollie222’s picture

I believe I've come across the same/a similar issue as Travis.

If I create a rule and try to select either of the VBO actions 'Load a list of entity ids from a VBO View.' or 'Load a list of entity objects from a VBO View.' then it looks like the browser tries to do an ajax update and then nothing happens.

In my case it throws a javascript error

Error: TypeError: Drupal.settings.better_exposed_filters.datepicker_options is undefined
Line: 93

The issue occurs with BEF beta 4 and the dev version dated 22nd May 2014.

My rule doesn't display a datepicker and as per Alex's comment in #5 setting $bef_add_js default to FALSE on line 584 of better_exposed_filters_exposed_form_plugin.inc allowed the rule editor to work correctly.

mrP’s picture

I was experiencing the same javascript error as reported by others. My problem was simply editing views exposed form BEF settings. It would process as if the settings were going to load and then never appear.

alexweber's solution in #5 worked fine for me.

botanic_spark’s picture

The patch #1 fixed my js error.

mikeker’s picture

Status: Needs review » Postponed (maintainer needs more info)

Can you try the latest -dev version of BEF. I suspect the fix for #1841452: Javascript error: Uncaught TypeError: Object #<Object> has no method 'datepicker' will fix this issue as well.

mikeker’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Issue queue cleanup... I'm assuming that #10 is correct and the problem was fixed.

If you're still seeing this, please reactivate with specific steps to reproduce. Thanks!