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
- Create a role with default rights + "Add Article content".
- Create an user and assign it the created role.
- Login with the created user.
- Go to the /node/add/article.
- 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
Comment #2
TheRec commentedRe-roll due to #505084: Add #attached_library FAPI property for drupal_add_library().
Comment #3
TheRec commentedPosting the patch would make it easier to get it reviewed :P
Comment #5
lilou commentedHEAD is broken.
Comment #6
cliffIs 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 ?
Comment #7
TheRec commentedErr.. 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.
Comment #8
cliffOK, 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 .
Comment #9
TheRec commentedOf 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.
Comment #11
TheRec commentedRe-rolling. The Javascript error still happen and procedure to replicate is still the same.
Comment #12
dave reidAdding tag
Comment #13
Oakfellow commentedI 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.
Comment #15
Oakfellow commentedResubmitting patch as a unification of the two.
Comment #17
Oakfellow commented3rd try at uploading this patch. Bear with me, it's my first time.
Comment #18
robloachI like it! I'd like it even more if you did this so that data() isn't called twice... :-)
Comment #19
Oakfellow commentedDone and done!
Comment #20
robloachWatch out for the killer whitespace! RTBCed.
Comment #21
sunHm. 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?
Comment #22
robloachPushing to critical as anonymous users can't use the node add page without this fix.
Comment #23
robloachWhoa, sorry. Needs an update to HEAD.
Comment #24
robloachUpdated to HEAD.
Comment #25
sunAre 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!
Comment #26
robloachYou 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.
Comment #27
sun...which makes it less critical.
The "else" is superfluous. However, I'd even recommend to reverse the !empty() condition and turn this into an early-out.
Is there a reason for why we add this in a theme function and don't use #attached?
Powered by Dreditor.
Comment #28
heather commentedJust tested and the empty div is gone.
See before:
See after.. Text format info does look a teeny bit too close to the button on a page creation form...
Looks fine on an article create form because of the tags:
Otherwise does what it says on the tin!
Comment #29
aspilicious commentednot yet RTBC
Comment #30
heather commentedSorry... 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.
Comment #31
robloachThis cleans it up a bit by moving over to #post_render to inject the #attached library. Also switches to theme('container').
Comment #32
aspilicious commented#31: 551426.patch queued for re-testing.
Comment #33
retester2010 commented#31: 551426.patch queued for re-testing.