Symptoms

Javascript Error:

Error : focus.data("verticalTab") is undefined
Source File : http://localhost/drupal-HEAD/misc/vertical-tabs.js?7
Row : 44
Page : <em>/node/add/<node_type></em>

Reproduce this bug

  1. Create a role with default rights + "Add Article content".
  2. Create an user and assign it the created role.
  3. Login with the created user.
  4. Go to the /node/add/article.
  5. Check the Javascript Error console.

Causes

The Vertical Tabs wrapper is added althought there is no tab to render, due to lack of permissions.

I located where this could be fixed for the node system, but this might be more useful to fix it on theme_vertical_tabs, where the Javascript is added, so it does not output a vertical tab wrapper when there is no tab that will be output (for the same reason or another). The following patch does this, and returns an empty string if there is no tabs to render. It also avoids an useless empty wrapper.

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

TheRec’s picture

Status: Needs work » Needs review
TheRec’s picture

StatusFileSize
new919 bytes

Posting the patch would make it easier to get it reviewed :P

Status: Needs review » Needs work

The last submitted patch failed testing.

lilou’s picture

Status: Needs work » Needs review
cliff’s picture

Is this a duplicate of at least part of the work entailed in #357300: Place all top level form elements into a default vertical tab group?

And how does this tie in to the effort to ensure that vertical tabs are accessible — #467296: Accessibility improvements for vertical tabs ?

TheRec’s picture

Err.. seriously, I don't know what you mean... this is just a bug when someone tries to render vertical tabs when none is actually going to render (because of lack of permission)... I don't think it has anything to do with the issues you've mentioned.

cliff’s picture

OK, maybe I'm misunderstanding the way the pieces fit together. It's just interesting to me that the same issue — lack of permissions leading to rendering problems — was discussed and hacked on in #357300: Place all top level form elements into a default vertical tab group. Nobody participating in this issue is also participating there, so it seems that if each of you were to read the other's thread, you might get one (or both) issues solved.

And how Javascript handles the tabs and their operation appears to be essential to not only that issue but also #467296: Accessibility improvements for vertical tabs .

TheRec’s picture

Of course I've read the issues before answering to you earlier. All my issue wants to address is that whenever and however a vertical tab is rendered and there is absolutely no tab that could be rendered, it should just not add the Javascript and not echo empty wrappers. The issues you mention are working on a lower level (before rendering is done) and are already much more complicated, adding what the patch in #3 does to either of those issues would not get is many chances for it to go in quickly and might very well delay them to get in.

Status: Needs review » Needs work

The last submitted patch failed testing.

TheRec’s picture

Status: Needs work » Needs review
StatusFileSize
new982 bytes

Re-rolling. The Javascript error still happen and procedure to replicate is still the same.

dave reid’s picture

Issue tags: +vertical tabs

Adding tag

Oakfellow’s picture

StatusFileSize
new325 bytes

I ran into an offshoot of this bug -- collapsible fieldsets don't work in node edit dialogs for users without privileges that necessitate a vertical-tab (the javascript error mentioned in this report prevents interacting with collapsible fieldsets). This seems rather major to me... but must be most sites either don't use collapsible fieldsets there, or all users have some privileges.

My one concern is that by fixing this at the theme level, we leave the javascript error unattended (if someone creates a vertical-tab div manually, or overrides the theming it will still pop up). I'm attaching a javascript patch (hopefully I'm doing it right) to prevent the error. I think both of these fixes used together is the best solution to the bug.

Status: Needs review » Needs work

The last submitted patch, 551426-vertical_tabs_empty_focus.patch, failed testing.

Oakfellow’s picture

Status: Needs work » Needs review
StatusFileSize
new1.5 KB

Resubmitting patch as a unification of the two.

Status: Needs review » Needs work

The last submitted patch, nodes-551426-vertical_tabs_empty_focus-14.patch, failed testing.

Oakfellow’s picture

Status: Needs work » Needs review
StatusFileSize
new1.57 KB

3rd try at uploading this patch. Bear with me, it's my first time.

robloach’s picture

I like it! I'd like it even more if you did this so that data() isn't called twice... :-)

       if (!focus) {
         focus = $('> .vertical-tabs-pane:first', this);
       }
-      focus.data('verticalTab').focus();
+     // Only try and get focus if there is a tab.    <--- Also remember punctuation! :-)
+     var verticalTab = focus.data('verticalTab');
+      if (verticalTab != undefined) {
+        verticalTab.focus();
+      }
     });
   }
 };
Oakfellow’s picture

Done and done!

robloach’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.56 KB

Watch out for the killer whitespace! RTBCed.

sun’s picture

Hm. Same but slightly differently applied fix for the JS lives in #679530-5: administer filters permission should not affect text format widget - testing focus.length should be sufficient based on my testing?

robloach’s picture

Priority: Normal » Critical

Pushing to critical as anonymous users can't use the node add page without this fix.

robloach’s picture

Status: Reviewed & tested by the community » Needs work

Whoa, sorry. Needs an update to HEAD.

robloach’s picture

Status: Needs work » Needs review
StatusFileSize
new1.73 KB

Updated to HEAD.

sun’s picture

+++ misc/vertical-tabs.js	15 Mar 2010 17:49:54 -0000
@@ -42,7 +42,11 @@ Drupal.behaviors.verticalTabs = {
       if (focus.length) {
-        focus.data('verticalTab').focus();
+        // Only try and get focus if the tab truly exists.
+        var verticalTab = focus.data('verticalTab');
+        if (verticalTab != undefined) {
+          verticalTab.focus();
+        }
       }

Are you sure that this is still required? The focus.length condition got introduced in one of my other patches (mentioned above) and should prevent the JS error already

145 critical left. Go review some!

robloach’s picture

StatusFileSize
new1.02 KB

You make a good point. The focus.length check will do it for us. We don't really want verticaltabs.js, or the empty div if there arn't any Vertical Tabs though.

sun’s picture

Priority: Critical » Normal

...which makes it less critical.

+++ includes/form.inc	15 Mar 2010 17:49:53 -0000
@@ -2652,10 +2652,17 @@ function form_process_vertical_tabs($ele
+  // Return HTML only if at least one of the tabs has been rendered.
+  if (!empty($element['group']['#children'])) {
...
+  else {
+    return '';
+  }

The "else" is superfluous. However, I'd even recommend to reverse the !empty() condition and turn this into an early-out.

+++ includes/form.inc	15 Mar 2010 17:49:53 -0000
@@ -2652,10 +2652,17 @@ function form_process_vertical_tabs($ele
+    // Add required JavaScript and Stylesheet.
+    drupal_add_library('system', 'vertical-tabs');

Is there a reason for why we add this in a theme function and don't use #attached?

Powered by Dreditor.

heather’s picture

Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

Just tested and the empty div is gone.

See before:

Only local images are allowed.

See after.. Text format info does look a teeny bit too close to the button on a page creation form...

Only local images are allowed.

Looks fine on an article create form because of the tags:

Only local images are allowed.

Otherwise does what it says on the tin!

aspilicious’s picture

Status: Reviewed & tested by the community » Needs review

not yet RTBC

heather’s picture

Priority: Critical » Normal

Sorry... oh dear I need to be more careful.

I didn't mean to mark this as critical or RTBC. Still needs a little work, I think, as demonstrated above.

robloach’s picture

StatusFileSize
new2.61 KB

This cleans it up a bit by moving over to #post_render to inject the #attached library. Also switches to theme('container').

aspilicious’s picture

Issue tags: -vertical tabs

#31: 551426.patch queued for re-testing.

retester2010’s picture

#31: 551426.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 551426.patch, failed testing.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.