Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By tce on
In a custom module, does anyone know how I could go about disabling the table drag functionality for some of the fields in node edit? I don't want the user to be able to change the weights.
Comments
I'd really like to know this
I'd really like to know this as well. I would have thought it would be a setting.
It seems table dragging is
It seems table dragging is added using the function drupal_add_tabledrag(). Looking at the code, the Javascript file is added to add the functionality. So disabling it is a case of removing this file. In a module I did the following...
Obviously, you'd want a condition in there so it only deletes if for the form you want. Also, that removes it for ALL tables, if you want to remove it for a single table you need to find the reference to the tabledrag in $javascript['settings]['data'] and unset that instead.
If you remove this file that
If you remove this file that will disable drag functionality for the entire page load. The problem is disabling tabledrag for certain fields, or just a particular set of weighted rows.
Good point. Another idea
Good point. I think
settings.tableDrag
decides if the table is draggable or not. Maybe manipulating that will help.If you look at drupal_add_tabledrag(), it adds it doing the following:
Maybe using a hook to remove this before being rendered would work, possibly using hook_js_alter()? How to do this for certain fields only I have no idea. Maybe go in and unbind events using JS.
That makes sense,
That makes sense, manipulating the Drupal.settings variable might be possible, I'll see if I can try it out myself.
Maybe in the longterm, a drupal_remove_tabledrag function can be discussed?
I had to do this in a profile
I had to do this in a profile field, I found this which worked perfectly:
http://www.commercialprogression.com/post/how-remove-tabledrag-rearrangi...
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
I tried your solution on a
I tried your solution on a image field but is not working, does it use other function than theme_field_multiple_value_form()?
I have tried it too. It is
I have tried it too. It is calling the function but still adding the drag and drop.
Did you sort it out either?
Thanks Jeff the solution in
Thanks Jeff the solution in that link worked :)
Awesome, thanks
This works great. Just dropped it into a custom module and worked like a charm.
Quick and Dirty solution **Not targeting fields**
Sorry for not addressing the specific question of targeting fields to disable tabledrag, but this issue is the most common search result on the subject in general.
For some reason, unset($javascript['misc/tabledrag.js']); does not work for me...
Jeff Burnz's solution is probably more elegant, but I was looking for a quick solution to disable tabledrag altogether and came up with this:
Where my_module/includes/nodrag.js is an empty file. Akin to removing the contents of tabledrag.js itself, but that would be hacking core.
Metatag should be in core.
A module for that
For anyone else finding this page, there is a module that implements the solution from http://www.commercialprogression.com/post/how-remove-tabledrag-rearrangi...
Module: No Table Drag
jeff's solution does not work
jeff's solution does not work for inline entity forms.
can disable per field
Module "Field lock multi values"
The module Field lock multi values has this feature for some fields, too:
Unfortunately (for me) it seems not to work for file-fields?!
Or for a much quicker
Or for a much quicker solution, just hide the drag handle using css.
Here's what worked for me
Here's what worked for me for a two-value field:
For Drupal 8
See this issue: #2264739: Allow multiple field widgets to not use tabledrag