When I am writing the UI for a module, often times I need to display the information in a table. Not a problem with theme_table. There are also times where that table needs to contain form API elements such as weights, buttons, textfields and so on. Currenly, one has to create the form, then set the #prefix and #suffix properties on particular elements, set the class of necessary rows and the table.
In order to simplify this process, I have written a function (form_table) that allows the developer to create form tables similar to the way you call theme_table. form_table will even handle the drupal_add_tabledrag for you (if the config is provided as a table attribute).
I've attached the source, example and a sceenshot of the example output. I'm looking forward to see if this is useful to anybody else.
Comment | File | Size | Author |
---|---|---|---|
#15 | tableform.patch | 7.39 KB | vangorra |
#12 | formtable.patch | 7.17 KB | vangorra |
#6 | form.inc_.patch | 10.56 KB | vangorra |
#4 | form.inc_.patch | 10.69 KB | vangorra |
form_table.tar_.gz | 26.31 KB | vangorra |
Comments
Comment #1
tutumlum CreditAttribution: tutumlum commentedI liked it. I was looking for something similar. I am starting to use it now for my new-developing modules :)
Thanks a lot...
Comment #2
tutumlum CreditAttribution: tutumlum commentedComment #3
catchPlease attach this as a patch rather than a tarball. Also have you looked at the tableselect property in Drupal 7? Not sure how much that might cover what you're doing here.
Comment #4
vangorra CreditAttribution: vangorra commentedHere is the patch to be applied against includes/form.inc. I was thinking of replacing $attributes on theme_table with $options['attributes'], so more config options can be passed to the function cleanly. What do people think? Any other suggestions?
Comment #6
vangorra CreditAttribution: vangorra commentedSorry, I didn't include the relative path in the patch.
Comment #7
kika CreditAttribution: kika commentedSorry for junk followup, but do we need all these junk tags? At least "D7", "form" and "patch" are totally unneccessary.
Comment #8
vangorra CreditAttribution: vangorra commentedProbably not, I'm not familiar with the preferred tagging convention.
Comment #9
Frando CreditAttribution: Frando commentedI didn't look at the patch in much detail, but for this to be considered it really has to be a regular form element that can be used by setting the #type (or #theme) property on an element. And it should be merged with tabeleselect, for sure. Also, please correct the coding style (see our coding standards), e.g. Drupal doesn't do tabs nor @author doxygen tags.
Edit: See also #297893: #theme Form elements into tables and #80855: Add element #type table and merge tableselect/tabledrag into it. I smell duplicates..
Comment #10
vangorra CreditAttribution: vangorra commentedAfter reviewing form_tableselect, I can see where merging form_table and form_tableselect would be beneficial. In doing so, the features of the function would no longer reflect the function name. I propose the creation of a "formtable" element. The theme_formtable function would render each column that is a form element. See element example below:
Any suggestions on how this could be improved?
theme_formtable element
Comment #11
moshe weitzman CreditAttribution: moshe weitzman commentedas frando said, please work at #80855: Add element #type table and merge tableselect/tabledrag into it. perhaps improve upon drumm's file there.
Comment #12
vangorra CreditAttribution: vangorra commentedHere is the patch that creates a new FAPI element called tableform. The following example demonstrates how to use the element. Please review it and provide me with any feedback how this can be made acceptable.
Thanks.
Comment #14
Bevan CreditAttribution: Bevan commentedComment #15
vangorra CreditAttribution: vangorra commentedHere is a patch based on CVS. This should pass the test. Again, here is an example on how to utilize the element type.
Comment #16
vangorra CreditAttribution: vangorra commentedBevan, what sort of usability tests do you recommend? How can I help?
Comment #17
vangorra CreditAttribution: vangorra commentedHas anybody had a chance to review this patch? I'd really like to see it get included in drupal7.
Comment #18
seb192 CreditAttribution: seb192 commentedhi
how i can install the patch?
thanks
Comment #19
catch@seb192 Please don't change versions back to Drupal 6 without a very good reason, that just makes patches drop out of the active (7.x) development queue.
@vangorra, the patch currently has a lot of code style issues (tabs etc.) which makes it harder to review. It'd be worth looking at http://drupal.org/coding-standards and/or running http://drupal.org/project/coder on it - if you can fix that up you're likely to get more meaningful reviews. You're also more likely to get reviews if you post your patch to #80855: Add element #type table and merge tableselect/tabledrag into it and close this issue as duplicate - since there's more discussion there, and several potential reviewers have already posted.
Comment #20
vangorra CreditAttribution: vangorra commented@catch Thank you for the feedback, that was very helpful. I have styled the codebase and submitted the patch to the suggested thread. I look forward to your feedback in the new thread.
The project is not dead, just closing this thread in favour of:
http://drupal.org/node/80855#comment-1981750
Comment #21
dropcube CreditAttribution: dropcube commentedDuplicate of #80855: Add element #type table and merge tableselect/tabledrag into it.