You are here

D8 Notes: Table Drag

While working on a ad placement module for clients (which I plan on releasing to contrib in the future), I noticed an interesting problem with table drag. If you put a table with tabledrag inside of your form builder method, then add certain fields as rows, those fields will always fail on validation. An example field is the datetime element. Thankfully there is a work around - theme wrappers!

Instead of defining the table inside of the form builder method, what you need to do is create an empty wrapper and add a theme to that wrapper. Then within that theme's preprocessor, you can define the table properties. For an example of how to do this, check out WidgetBase and for how this is handled in the Field's widget system.

It is a little more work, but will save you lots of headaches in the long run!