I get this javascript error "Uncaught TypeError: Object #

has no method 'datepicker'". According to file "better_exposed_filters_exposed_form_plugin.inc" js file "better_exposed_filters.js" can be included in two cases first case: better_exposed_filters_exposed_form_plugin.inc line 867 We adding BEF's JavaScript to the mix to handle select all/none functionality second case: better_exposed_filters_exposed_form_plugin.inc line 922 We adding Datepicker JS and CSS. And according to line 918 we always have "bef_datepicker" js setting for each view, if we have exposed filter. Default it set on FALSE. But if variable $add_datepicker is TRUE, we set "bef_datepicker" on TRUE and include Datepicker library(ui.datepicker) and include js "better_exposed_filters.js". Next, if we need ajax render page with several views with exposed filters, "bef_datepicker" setting becomes array of boolean values(NOTE! It possible with AJAX render only). I get situation with rendering 5 views, when "better_exposed_filters.js" was included on line 867, but "$add_datepicker" variable was false 5 times, and "bef_datepicker" setting becomes array of 5 false values. So I get included "better_exposed_filters.js" without included Datepicker library! Next, if "better_exposed_filters.js" is included, it check "bef_datepicker" setting on line 86. Array of false values casts in TRUE. So next javascript check "bef_dateformat" and then try to apply method "datepicker" to "bef-datepicker" class, and get error, because "Datepicker" library is not included, and "datepicker" method is not available. So I propose additional check on "bef_dateformat". According to "better_exposed_filters_exposed_form_plugin.inc" 921-928 lines "bef_dateformat" always is defined if "Datepicker" library was included. So checking "bef_dateformat" on "undefined" value is sufficient condition. Sorry for my English
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, better_exposed_filters.js_.patch, failed testing.

andypost’s picture

+++ b/better_exposed_filters.jsundefined
@@ -83,7 +83,8 @@
+      if (Drupal.settings.better_exposed_filters.bef_datepicker && ¶

trailing whitespace!

kalistos’s picture

Status: Needs work » Needs review
FileSize
632 bytes

whitespaces trimmed

Status: Needs review » Needs work

The last submitted patch, 1841452_better_exposed_filters_3.patch, failed testing.

andypost’s picture

Version: 7.x-3.0-beta3 » 7.x-3.x-dev
Status: Needs work » Reviewed & tested by the community

It looks that tests are broken. We have no JS testing for now anyway

+++ b/better_exposed_filters.jsundefined
@@ -83,7 +83,8 @@
+        typeof Drupal.settings.better_exposed_filters.bef_dateformat !== 'undefined') {
         // Note: JavaScript does not treat "" as null

makes sense because this settings variable could be undefined

kalistos’s picture

Comment added

gynekolog’s picture

#6 works, thank you.

maximpodorov’s picture

Status: Reviewed & tested by the community » Needs review
andypost’s picture

Status: Needs review » Reviewed & tested by the community

@maximpodorov we have 3 reviews and no JS testing, so back to rtbc

kehan’s picture

Indeed the patch works for me too

sgabe’s picture

I can confirm that the patch in #6 applies and works fine!

mikeker’s picture

Status: Reviewed & tested by the community » Fixed

Commited.

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

maximpodorov’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review
FileSize
1005 bytes

Currently, BEF won't show datepickers. Additional patch is needed.

kalistos’s picture

Status: Needs review » Reviewed & tested by the community
maximpodorov’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.05 KB

One more check is needed. Please apply this patch and the patch from #1961486: Latest dev release + slider breaks views UI javascript since incorrect JavaScript breaks many things, including Rules UI.

maximpodorov’s picture

@mikeker
Please apply this simple fix.

mikeker’s picture

Status: Needs review » Fixed

The underlying problem was that the BEF settings being set in the plugin had gotten out of sync with what was expected in BEF's JS code. An adapted version of your patch was committed along with a major revamping of the automated tests for this project.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

markusk’s picture

Status: Closed (fixed) » Needs work

Have to reopen the issue as it still persists in 7.x-3.0-beta4+6-dev. Same JS error is thrown when you use a BEF enabled view.

Very annoying side effect: a single view with BEF enabled makes VBO actions in Rules unusable as it breaks Rules' UI. Had to disable BEF because of that.

tisteegz’s picture

I am also having a datepicker issue. I am currently on 7.x-3.0-beta4 and cannot use my view with Ajax enabled otherwise I get the following error.

Uncaught TypeError: Cannot read property 'dateformat' of undefined.

Even though I am not using Dates at all.

donutdan4114’s picture

I have this issue as well:
Uncaught TypeError: Cannot read property 'dateformat' of undefined.

I don't have anything that requires a date picker in my view...

firfin’s picture

Same error here. Strange to notice I couldn't go to the BEF settings in my views page display (although it worked on the master display) so it wasn't possible to re-save these settings.
Workaround for me was reverting to beta3. No problems then.

maximpodorov’s picture

Status: Needs work » Needs review
FileSize
564 bytes

This patch adds datepicker library existence check.

firfin’s picture

Aplying the patch cleared up the error message about 'datepicker'.
Also it seems sensible to have this check in place anyway.

However, I get another error after applying the patch ( ' Uncaught TypeError: Cannot read property 'length' of undefined' ) I hoped this would be easily fixed by disabling 'jQuery update' module, and then the BEF settings worked as expected. Unfortunately this wasn't the case.

thanks for a valiant effort @maximpodorov !

maximpodorov’s picture

Where do you get ' Uncaught TypeError: Cannot read property 'length' of undefined' error?

legittalon’s picture

I've updated this patch to also fix the jQuery 'Uncaught TypeError: Cannot read property 'length' of undefined' error. Now AJAX stuff inside views should work properly

firfin’s picture

Patch from #27 @legittalon works for me (with beta 4). No more errors.
Updating status.

firfin’s picture

Status: Needs review » Reviewed & tested by the community
maximpodorov’s picture

Status: Reviewed & tested by the community » Needs work

Why do you mix slider and datepicker? There is another issue related to slider: #1961486: Latest dev release + slider breaks views UI javascript.

firfin’s picture

Sorry bout the mix up @maximpodorov I just know the patch provided in #27 solved my problems (or at least seems to).

TravisJohnston’s picture

I tried the patch in #27 with no luck. I am having a similar problem when I try to load View Bulk Operations into Rules, when I go to create an Action Set, and click Add Action and choose the "Load a list of entity..." (either one of the 2 that show) the "please wait" toggle starts spinning then nothing happens.

Looking at the console log I see this:

Uncaught TypeError: Cannot read property 'dateformat' of undefined
Source is from VM788 line 198 typeof Drupal.settings.better_exposed_filters.datepicker_options.dateformat !== 'undefined') {

I tried updating BEF to latests dev branch, applied the patch in #27, but that didn't work.

alex.druhet’s picture

Here is a simple workaround that can bring your filters back: just use the 7.x-3.0-beta3 version of better_exposed_filters.js. As a temporary hack, add it to template.php in your theme with hook_js_alter :

/**
 * Implements hook_js_alter().
 */
function YOUR_THEME_NAME_js_alter(&$javascript) {
  $bef_js_path = drupal_get_path('module', 'better_exposed_filters') . '/better_exposed_filters.js';
  if (isset($javascript[$bef_js_path])) {
    $javascript[$bef_js_path]['data'] = drupal_get_path('theme', 'YOUR_THEME_NAME') . '/js/better_exposed_filters.js';
  }
}
TravisJohnston’s picture

Hey Alex,

Thanks for your reply. I did was you said and swapped out the js file with the newest 7.3 beta, (and cleared caches), and I am still getting a spinning wheel that just stops and nothing happens. Console still says the dateformat is undefined.

UPDATE: Hold on, I just checked the Sources log, and it's still loading the modules JS instead of the one in my theme.

TravisJohnston’s picture

Hey Alex,

For the heck of it, to not waste time looking at why my version of the JS didn't load, I replaced the code in the current JS file with the new one and tried that. Still no change, same dateformat error. Am I missing a step? I am still using the latest Dev branch for the core module files. It's still having trouble with the following undefined:

// 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') {
        // Note: JavaScript does not treat "" as null
        if (Drupal.settings.better_exposed_filters.datepicker_options.dateformat) {
          $('.bef-datepicker').datepicker({
            dateFormat: Drupal.settings.better_exposed_filters.datepicker_options.dateformat
          });
        }
ufku’s picture

Status: Needs work » Needs review
FileSize
2.03 KB

Fixed the usage of Drupal.settings.better_exposed_filters.

bendev’s picture

#36 works as expected.
thanks

Plazik’s picture

#36 works on dev version for me too.
Thanks.

mikeker’s picture

Status: Needs review » Fixed

Thanks, everyone, for your patience on this issue.

The fix in #36 has been committed.

  • mikeker committed 1319a7d on 7.x-3.x
    Issue #1841452 by maximpodorov, kalistos, ufku, legittalon: Fixed...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.