For some reason when i visited my site today, on one of my content types i found several errors.

1. My geolocation map on the node/add page has dissapeared
2. When i click on the Browse button for the media browser it doesnt pop up
3. The admin menu has gone from the top of the page to the bottom of the page
4. My WYSIWYG editor doesnt appear

Using Firebug i can see one error, and it says:

ReferenceError: compare is not defined
return compare(reference, value);

It is refering to the file /sites/all/modules/conditional_fields/js/conditional_fields.js?mlfdsp on line 36 which is:

return compare(reference, value);

Can someone help me? I really appreciate it

note. this only happens on one content type, one the rest of my content types i have WYSIWYG editors, maps and media browsers and all work fine.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

prezaeis’s picture

Just to note, switching conditional fields module off fixes my problems, so i know this is causing it

jackdaniel9’s picture

We had the same problem

Go to "Manage Dependecies"

Change ===== Context Setting -> Effect -> FadeIn / FadeOut to Show/ Hide

When you active FADEIN / FADEOUT :

Jquery Fail error "Compare" line 36

math_1048’s picture

Issue summary: View changes
FileSize
54.39 KB

Hello,
I have this issue with Conditional field + Geolocation as shown in the picture
I think map need to be refreshed by some way...
please help me to fix this issue.
thanks and regards

jcmartinez’s picture

This is still happening when the effect is either slide or fade. It goes away when the conditional fields are using show/hide; so I'm switching mine for now to show/hide.

After inspecting the tag I noticed that some @import are missing when it doesn't work, mainly:

jquery_update/replace/ui/themes/base/minified/jquery.ui.core.min.css
jquery_update/replace/ui/themes/base/minified/jquery.ui.theme.min.css
jquery_update/replace/ui/themes/base/minified/jquery.ui.datepicker.min.css

Also, if you have configured more than one conditional field for the same content type the problem will not go away until you reconfigure all the conditionals to use show/hide.

Since I don't understand why this is happening I leave it here in case someone has any ideas.

Anybody’s picture

I can confirm this problem exists and is truely critical.

It appears in line 36 of conditional_fields.js due to a missing "compare" function dependency. Here's the code where the error happens:

/**
 * Handle Object values.
 */
Drupal.states.Dependent.comparisons['Object'] = function (reference, value) {
  /* Regular expressions are objects with a RegExp property. */
  if (reference.hasOwnProperty('RegExp')) {
    reference = new RegExp(reference.RegExp);
    return this.RegExp(reference, value);
  }
  else {
    return compare(reference, value);
  }
};

Where does that "compare" function come from and how can we simply include it?

Anybody’s picture

Assigned: prezaeis » Unassigned
Category: Support request » Bug report

BTW: The problem appears in the latest 7.x DEV and stable version.

Anybody’s picture

BTW2: All effects are already set to Show / Hide on my page. This is not a workaround for me.

Anybody’s picture

I finally invested some hours to investigate this in deep and finally it seems this may never have worked!

The technical reason for the problem is, that the compare() function, defined in Drupal core states.js is never accessible from conditional_fields.js!
function compare() is defined within the jQuery scope and not as global as it seems though.

I could not find a way to call compare() without hacking states.js and putting the "global" functions out of jQuery scope (behind closing "})(jQuery);").
Here you can find some more information the scope problem: https://www.sitepoint.com/community/t/jquery-calling-function-from-other...

So finally I found a workaround that should not have any negative impact but should fix the issue finally: We can access Drupal.states.Dependent.comparisons from conditional_fields.js which allows us to call the function:

Drupal.states.Dependent.comparisons.Number(reference, value);

which then calls compare() from within its scope!
That finally does what it should. => compare by value.

Here's my suggestion for a fix in conditional_fields.js:

/**
 * Handle Object values.
 */
Drupal.states.Dependent.comparisons['Object'] = function (reference, value) {
  /* Regular expressions are objects with a RegExp property. */
  if (reference.hasOwnProperty('RegExp')) {
    reference = new RegExp(reference.RegExp);
    return this.RegExp(reference, value);
  }
  else {
	// Do plain text comparison instead:
	// We use number as workaround for indirect plain text comparison.
	// The global "compare()" from states.js should be called directly here,
	// but that is not possible because it is bound to the jquery namespace 
	// within states.js and not accessible from here!
    return Drupal.states.Dependent.comparisons.Number(reference, value);
  }
};

Please review this and / or create a patch, if the solution is viable.

Thank you very much!

Anybody’s picture

Status: Active » Needs review
FileSize
908 bytes

Here's the patch from #8:

oschuetze’s picture

#9 works fine for me. Thanks!

sudishth’s picture

Status: Needs review » Reviewed & tested by the community

#9 is working for me

nachenko’s picture

#9 works for me too

DanStorm’s picture

Oddly, this issue appeared for us after updating core from 7.63 to 7.66 ¯\_(ツ)_/¯ and #9 fixed it for us.

mavmark’s picture

#9 TOTALLY fixed it for me. I spent hours digging through code and forums trying to find the answer. Thank you!

Anybody’s picture

Thank you, any plans for a commit? Any active maintainer?

Anybody’s picture

dqd’s picture

Thanks for all the hard work in here, the reports, the efforts, the new investigations regarding the underlying issue. All very much appreciated.

Reviewed and tested and committed to latest 7.x dev. Hope it still helps someone out there! But please consider updating Drupal to latest core since EOL of Drupal 7 is coming soon.

  • dqd committed 3d33c7f3 on 7.x-3.x authored by Anybody
    Issue #1973320 by Anybody, prezaeis, dqd: Module has broken my node/add...
dqd’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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