If you create a book and then go to "edit order and titles" you will generate the following error:
$(".indentation", testCell).get(1) is undefined (Line 80)
this.indentAmount = $('.indentation'...dentation', testCell).get(0).offsetLeft;
This may seem minor because why would anyone edit titles in a book if there isn't anything there? Well, it's a js bug which then stops all js on the page from functioning correctly. I only noticed it as I'm writing a module to add functionality to the books edit page and wanted to add in a button for just this use-case of having no children nodes.
Comments
Comment #1
mr.baileysConfirmed that this bug still exists in 7.x-dev (so should be fixed there first and then backported).
The bug is not limited to just the book module, but rears its head anytime you have a draggable table with 0 rows. The current code in tabledrag.js does not correctly handle empty tables (it performs actions on the first draggable row, without ensuring it exists):
One option might be to create an extra row in the table with the draggable class (and visiblity set to hidden), determine the indentAmount using that row, and then removing it again?
Comment #2
btopro commentedcouldn't a simpler test be done before this statement runs to test the number of children found in the table. If it's 0 then....don't run anything?
Comment #3
mr.baileysThat was my first thought, but there is the off chance that rows are added dynamically to a table later on, which made me wonder if it wouldn't be better to come up with a safer way of determining indentAmount, instead of skipping it when no rows are present...
Don't know enough about this to determine the right course of action though...
Comment #4
kmontyI am also having this issue with Drupal 6.x.
Subscribe
Comment #5
Anonymous (not verified) commentedI've just run into this issue. I think mr.baileys' point in #3 is valid. So, I think the indentAmount calculation should be skipped if the table has no children, but the calculation should be ran on the context variable in the Drupal.behaviors.tableDrag method each time. That way, if the DOM changes, and Drupal.attachBehaviors() is properly called, things will still work.
I will try and write a patch for this sometime soon. Let me know if anyone thinks there is something I'm missing.
This is a real annoying issue, because admin_menu and the devel themer box both disappear on the 'Manage Fields' page in CCK because JavaScript dies.
Comment #6
Anonymous (not verified) commentedOK, here is the patch I came up with. Instead of messing with the indentAmount property calculation, I just added a quick check to see if the table is empty (i.e. <table> contains no <tr> descendants with <td> descendants) before creating a new tableDrag object for that table and marking it as processed.
This way, if a module sends out an empty draggable table and then changes the DOM latter by adding draggable rows, it can run Drupal.attachBehaviors() to create the necessary tableDrag object for its table.
This is my first core patch, so feel free to yell at me if I'm not doing something right =)
Comment #7
Anonymous (not verified) commentedOn second thought...
My last patch will work, but I think it would be better if the selector used to test for draggable rows was the same one used later in the code, so here is a new patch. Should behave the same way.
Comment #8
Anonymous (not verified) commentedFor people having this issue in Drupal 6, here is my backported patch.
Comment #10
joshmillerThe bug went away for me when I turn off Devel Themer module. Changed title as this is most likely a collision of contrib and core, not just book. I found the bug on /admin/content/node-type/page/fields
Josh
Comment #11
kenorb commentedPatch #8 doesn't work for 6.x for me, disabling Devel Themer helped.
Comment #12
sholn commentedsame error with Drupal 6.x, d I've solved disabling Theme Devel module
Comment #13
buckley commentedDisabling the "Themer Info" solved the problem (I don't mean unchecking the checkbox but choosing "Disable Theme developer" in the Development block.
There seems to be a conflict between the handles and the themer info.
This is what IE said :
get(...).offsetLeft' is null or not an object
This is the case in Drupal 6.14
Comment #14
cecshab commentedSame here hopefully, devel will fix it soon.
Comment #15
kenorb commentedRelated issue: #663068: $(".indentation", testCell).get(1) is undefined
Comment #16
btopro commentedI assure you devel is not related to this issue as I've never used it and am able to replicate the error
Comment #17
smartango commentedDRUPAL 6
Ok, but being the problem void row, I just removed it in Drupal.tableDrag function, before anything else:
$('> tbody > tr.draggable, > tr.draggable', table)
.filter(function(index) {return $("td", this).length == 0;}).remove();
but I think this should be solved in table generation in cck/theme/content-admin-field-overview-form.tpl.php
I added a default case in switch to print
it print:
stdClass Object ( [weight] => [parent] => [hidden_name] => [label_class] => label- [row_type] => [indentation] => [class] => draggable )
... somewhere someway this kind of row are added, and is not a perfect behavior
check if this is the case for drupal 7
Comment #18
btopro commentedI also "solved" this bug in the outline designer module by checking a book for the existence of a page. If it doesn't have any children then it forces you to make a page before redirecting you back to the outline. Doesn't solve the JS issue but at least stops the glitch from occurring by eliminating the ability for it to occur.
Comment #19
goron commentedI believe this is a duplicate of #737596: tabledrag.js: $(".indentation", testCell).get(1) is undefined, which has been fixed.