When in node edit page, I get this error in console

TypeError: tags.val(...) is undefined
if (tags.val().indexOf(keyword) != -1) {

Tag suggestions appear below the opencalais fields but clicking on them there is no toggle effect (tags aren't inserted/retrieved in the corresponding field.
this error prevents other scripts to work correctly: 1) The page title (node title) is displayed as <em>Edit</em> myNodeTitle instead of Edit myNodeTitle (em is not rendered); 2) wysiwyg toggle enable/disable rich text editor is not displayed at all.
After disabling opencalais module 1) and 2) work as expected

I can't see what's going wrong. Using latest dev version (7.x-1.0-alpha2+22-dev) but had the same problem with 7.x-1.0-alpha2 stable. With the sable version I can resolve the problem setting jquery to 1.7 for admin, but this is not enough with the dev version.

Edit for adding some more info:
above behavior is when OpenCalais setting "Collect Tags into Vertical Tab" is checked. If this setting is not checked, there is no more console error, but problem 1) remains ("em" tag not rendered in page edit title), problem 2) disappears and finally 3) tag links behave correctly but autotagging still doesn't work (I mean we can click on tags bellow field and fill/unfill the field but fields are not pre-filled automatically neither on page edit load nor on clicking the "suggest" button)

CommentFileSizeAuthor
#9 jquery-erros-tags.val_.9.patch513 bytesElusiveMind
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

erwangel’s picture

Issue summary: View changes
erwangel’s picture

Issue summary: View changes
erwangel’s picture

Well, autotagging issue was resolved following https://www.drupal.org/node/2204311 instructions (old variable_get 'opencalais_autotagging' instead of new 'opencalais_settings').
I'm not very familiar with patches but there are just 4 occurrences in openclais.module, so instead of waiting when I could provide one (if I do it), someone can go on making it faster :

//    $auto = variable_get('opencalais_autotagging', array());
  $settings = variable_get('opencalais_settings', array());
  $auto = (array_key_exists('autotagging', $settings)) ? $settings['autotagging'] : array();

The problem is still there if "Collect Tags into Vertical Tab" is checked, but I think this is an issue with jquery code not with php one.

ElusiveMind’s picture

Status: Active » Closed (cannot reproduce)
erwangel’s picture

Perhaps I didn't described the issue correctly and it is not easy to reproduce, but this error remains.
I disabled some modules (radioactivity, field_group, og) that I suspected conflicting with open_calais but this didn't change anything, the error was still there. The main effect are:
- tags are not inserted in their fields even they appear as suggestions (event if I enter them manually they are not saved, so perhaps something has to do also with the presave hook)
- Wysiwyg is not toggle enable/disable rich text editor is not displayed (disabling open_calais brings back Wysiwyg editor)
So it seems the problem is coming from open_calais.
It seems like this error (in opencalais.node.js line 33)

TypeError: tags.val(...) is undefined
if (tags.val().indexOf(keyword) != -1) {

prevents other javascript to be read.

The problem doesn't happen in all content types but I could figure out why. I tried changing field's order with no result but I think something has to do with the order js files are read or loaded. At http://stackoverflow.com/questions/5006045/jquery-val-is-undefined there is an explanation "You probably included your JavaScript before the HTML" but that didn't helped.
Please leave this issue opened

erwangel’s picture

The "tags.val(...) is undefined" error is generated by function opencalais_form_node_form_alter on node types having multilingual option enabled (admin/structure/types/manage/[node type] > Publishing options) and also using entity_translation module.

around line 130 (function opencalais_form_node_form_alter) we have:

    $vars = array(
      'type' => $opencalais_type,
      'field_name' => $field_name,
      'suggestions' => $suggestions,
      'language' => $form['language']['#value']
//      'language' => $form[$field_name]['#language']
    );

    $themed_suggestions = theme('opencalais_suggestions', $vars);

The commented line is mine and it makes it work.

then in opencalais_suggestions.tpl around line 10 we have :

$for = 'edit-' . strtr(drupal_strtolower($field_name . '-' . $language), array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));

the $for is used to create the 'for' attribute of suggestion label which then is parsed by jquery in order to insert tags in the appropriate fields. In some cases $language is undefined and makes javascript blocking any later code.

In case mulitlingual option is enabled $form['language']['#value'] doesn't exist but we have access to $form['language']['#default_value']. $form['language']['#default_value'] is not a good option either because fields may be translatable or not (by entity_translation module or others) and result to the same language as the form language or remain to the LANGUAGE_NONE ('und') language. So we have to deal the language for each field separately and not give to all them the $form['language']['#value']. Otherwise the call to theme('opencalais_suggestions', $vars) will result to javascript errors.

More detailed discussion in my other issue which appears to have the same origin :
https://www.drupal.org/node/2556131

ElusiveMind’s picture

Assigned: Unassigned » ElusiveMind
Status: Closed (cannot reproduce) » Active
ElusiveMind’s picture

Instead of collecting them into a vertical tab, what if we put them in a collapsed fieldset (which could be selected to be collapsed or expanded by setting). This way it would not break Locale. It would change the interface, but would still work.

I'll code something up and put it up as a patch and we can see how it goes.

I am still not able to reproduce:

1) CKEditor disappearing
2) Javascript console errors

And I have ZERO doubt those two items are related. ANy more info you can give (jQUery versions, CKEditor versions, etc) would help so I can try to replicate the environment as best as possible. I will keep my eyes out though.

ElusiveMind’s picture

FileSize
513 bytes

Please see if the attached patch resolves the issue. It was made from items listed in this ticket by others.

ElusiveMind’s picture

Status: Active » Needs review

Please review with and without Locale turned on

ElusiveMind’s picture

This issue has been applied and is on the github. Once confirmed everything works will move here for next release.

https://bitbucket.org/mrbagnall/opencalais

  • ElusiveMind committed 0090571 on 7.x-1.x
    Issue #2751887 by erwangel: Undefined property: stdClass::$permid as $...
ElusiveMind’s picture

Now in the dev branch for review

erwangel’s picture

It works ! with 7.x-1.3+3-dev (2016-Aug-31). Thank you ElusiveMind !