Posted by bellHead on November 23, 2010 at 4:13pm
I have a module providing an extended checkboxes form element with an "Other please specify" entry. There is something along these lines for select boxes (which seems to be for CCK use only, not as a generic form element) but nothing I can find for checkboxes.
For completeness I suppose the module should also support radio buttons and connectors for the Fields UI. Since the first bit of useful functionality is there I'd say it's ready under the "release early and release often" philosophy.
Does this sound like it would be worth packaging as a contrib module?
Comments
We've often added "Other" as
We've often added "Other" as a checkbox/select box/radio button option with an accompanying, separate CCK text field for "Other please specify". I am curious to know whether the module would add any bells and whistles like validation etc.?
It has validation for
It has validation for checking that there is something specified if other is selected and the required check for the checkboxes field works correctly.
The main thing it does differently from the two field approach you describe is that the values from checked boxes and the value from the other field are returned together, so they are treated the same way in the validate and submit functions and would be put into same database field. One advantage of this is that an option which is added to the list at a later stage will integrate matching values specified under "Other" seamlessly.
I'm not sure how CCK would manage that behaviour, but the module would provide the function for raw module managed forms.
Thanks, That
Thanks,
That validation/integration stuff sounds great - obviously it's functionality that we are missing with our current solution. This module is probably not for us because we use CCK almost exclusively, but I'm sure others would benefit from it.
C
I might have something of use?
I've made something just like this for the Forms API in D6. The benefit is for validating that at least one answer has been supplied, and that if "other" is selected then some text has been entered into the "other" field, and the "other" option and textfield are added automatically to the element.
Makes it much easier to build forms that have many "other" checkbox elements :)
It already exists...
The Select (or other) module looks like it already does this. It supports radios, checkboxes, and select fields. Works with CCK, standard FAPI, and Webforms. Check it out and read the docs, might save you some time and effort!
... and in the event it doesn't do quite everything you need, it might be better to extend the existing module rather than write a whole new one. Again - saves you a lot of time and effort!
-R
I would also recommend
I would also recommend helping out the http://drupal.org/project/select_or_other project.
Senior Drupal Developer for Lullabot | www.davereid.net | @davereid
Got it!
I have posted a feature request issue to Select (or other) offering assistance on a 7 port.
I have to disagree on the extending a module saving time and effort over building a particular piece of functionality though, particularly across a version boundary. This is the thin edge of the module proliferation wedge though. It will almost always be easier to find samples in code to build on the core APIs than figure out a contrib module. A worthwhile contrib module will probably also address a wider problem than the one you immediately face, so some of the solutions may seem unnecessarily complex. Next thing you know there are 7.6E54 modules doing the same thing.
Don't know how to solve it but I will at least try not to be part of the problem this time :)
Ah, a D7 module...!
Stating that this need was for D7 from the get-go would have explained why you weren't interested in the existing D6 module - and would probably have elicited some different replies - to some extent.
I do applaud your offering to help with a D7 port of the existing module; it's still probably a good route to take even if you wind up writing your own D7 solution for your specific use-case. It will extend the life of an existing module so that sites can be more cleanly upgraded from D6 to D7 using the modules already installed vs having to reconfigure all the content types, forms, etc to accommodate a new field type and module.
IMHO, the more modules that offer this upgrade path, the less resistance there will be to upgrading existing sites. That's why the "D7 Pledge" is so big on all the D6 modules. I've already got requests in on one module I develop to port to D7 for that reason, and I've been coding to ease that transition for the past few months so it's as painless as possible to port when completed for D6.