Posted by texas-bronius on February 14, 2011 at 11:01pm
Is there another way besides hook_form_alter to add units labels to cck form fields? Units like "kWh", "kWh/month" or even pre-field like "$".
(I keep including "Central Texas" in these little Qs, but I wonder if they've all switched to Joomla out there .. ;) )
Thanks
-Bronius

Comments
why do you want another way?
Tedious? Can you recognize the suffixable fields programmatically? Could do it in the theme layer...
Seems like a "I Heart Science" cck field module to me
This could be presented by a CCK field.
The field would carry the units info, along with the scalar value.
That's how I'd do it in code. The quick way is probably to theme it, if the units don't change.
Mike
Measured Value Field
Might be right up your alley:
http://drupal.org/project/mvf
off the shelf MVF or hook_form_alter or theme layer
..all options seem viable to me at this point. To be honest, when I came across MVF + Units (reading only), I thought I might run into some overkill and I saw some concern with the only 222 installed uses-- is this really such a rare problem?
My labels are, as Jason pointed out, going to be consistent and very few, and I love his hackish way of thinking: I might be able to embed some clues into some property of the field itself. Hmm maybe a Label with naming convention like "Production|kWh" and a single hook_form_alter to split it up every time.. Or prettier, more appropriate, and less obtrusive should I miss translating it somewhere is in the fields' Help text fields. Would chx come out and personally hunt me down for that?
Mike-
Are you suggesting adding an additional cck field for every field that needs a units label and then "joining" them in the theme layer?
Thanks All, keep'm coming.
-Bronius
units and labels are included in the appropriate cck field type
cck fields of type number (integer, float, decimal) provide a nice mechanism for Prefix and Suffix great for $, kW/h, etc. Text fields get the shaft, but since (in my use case) the text fields with labels are the minority, I don't have a problem hackishing the the labels or prefixes if I need them at all.
Word the wise: Do not go and fill out text fields for data types to fill out content types just in order to meet sprint deadlines as "proof of concept". Converting data types in cck is not a task for the faint of heart. I had expected to do it with export->muck->import, but @FilmKnurd bested me with a hat tip to my presentation on Drush + Features workflow and proposed Featurizing -> muck -> revert. Much better (but not enough to make me want to do it again!).