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
Comment | File | Size | Author |
---|---|---|---|
#3 | dateformat-2236431-3.patch | 1.57 KB | mariancalinro |
#1 | dateformat-issue2236431-1.patch | 2.14 KB | tisteegz |
Comments
Comment #1
tisteegz CreditAttribution: tisteegz commentedI have made a patch adding my checks into the code which seems to remove the js errors.
Comment #2
tisteegz CreditAttribution: tisteegz commentedComment #3
mariancalinro CreditAttribution: mariancalinro commentedThe 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:
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.
Comment #4
alexweber CreditAttribution: alexweber commentedThis 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.
Comment #5
alexweber CreditAttribution: alexweber commentedI managed to get around that by making
$bef_add_js
default toFALSE
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.
Comment #6
TravisJohnston CreditAttribution: TravisJohnston commentedHey 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.
Comment #7
Ollie222 CreditAttribution: Ollie222 commentedI 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.
Comment #8
mrP CreditAttribution: mrP commentedI 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.
Comment #9
botanic_spark CreditAttribution: botanic_spark commentedThe patch #1 fixed my js error.
Comment #10
mikeker CreditAttribution: mikeker commentedCan 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.
Comment #11
mikeker CreditAttribution: mikeker commentedIssue 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!