Download & Extend

"Other" option in select lists for text entry

Project:Webform
Version:7.x-3.0-beta2
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Hi all,

I have a question on whether a "Select" form element could contain multiple textarea/textfield options for user to prompt for?

For instance, you have a select element such as this:

Describe what you like about Drupal:

Option1 - textarea/textfield
or
Option2 - textarea/textfield

I've noticed that today, you can chose between multiple checkboxes or a toggle switches but I could not figure out if a user can toggle a textfield in order to provide a free text area.

Thanks in advance,

Comments

#1

I'm not sure what's being asked here. From your sample it sounds like you just want two textareas, though the description of the request sounds like something else entirely.

I *think* the request is to have a select list with an "other..." option, which allows the user to enter free text?

This is a little hard to convey... something like this?
Sample:

Or am I completely off in my interpretation? I am really interested in implementing the scenario I'm describing, so I might just be projecting my own thoughts onto this request.

#2

Sorry for the confusion. I think you've nailed the *Other...* dropdown option which is exactly what I would like to accomplish. I would imagine that the same logic could be applied to a radio box or a checkbox as well. As a proof of concept, that is pretty much the idea. The user is presented with a question. Depending on the option he/she picks, a text box appears allowing the user to enter a free text.

Would you be able to provide me with a patch or a snipped on what I need to do to implement it?

Thanks you very much for a quick response!

Mike

#3

Depending on the option he/she picks, a text box appears allowing the user to enter a free text.

I'd like to note that this description makes the problem much more complex than I think we'd implement. I'm all for a special "other" field (which the user could give whatever title they want). However, I don't think we'd present users with the ability to have multiple options that did this. For that, see #254728: Conditional fields, which I'm not so enthusiastic about due to the complexity it would introduce.

But yes, I agree this should easily work with checkboxes or radios also. I'm not yet able to create a patch as it's going to take significantly more effort than that mockup, since it needs to work with storing the results, CSV downloads, results analysis, editing... you get the idea.

#4

Title:Creating multi-text select component element» "Other" option in select lists for text entry
Category:support request» feature request

Marking #263633: Adding a free response textfield to select component if no response. as duplicate, giving better name.

#5

Subscribing

#6

This would be a really huge asset.

#7

I'm looking for this too. For me it wouldn't have to be dynamically hiding/showing textfields depending on checked options.
An option containing a textfield would be enough. I know this would not be possible with a listbox, only with radios/checkboxes.
See attachment for an example.

For me simply adding an option like

key|option#textfield:15

(where 15 stands for length)

to a "select" component would be perfect.

AttachmentSize
survey_example.jpg 98.06 KB

#8

I don't think we'll add any more special syntaxes to the select list input box. Rather it'd just be a complete separate option:

Additional values:
[ x ] Add an "Other..." option for free text entry.

Additional values size:
[ 20   ]
The size of the textfield when using the the "Other..." option for free text entry.

#9

Very cool, this should work perfectly for just adding an unconditional "Other" textfield to an option list. I would certainly appreciate this feature.

#10

I would prefer both a textfield like outlned in #7 but I would also like a option for a textarea to appear below the select box. Because sometimes other is more then just 1 line of text.

Thanks
Robert

#11

quicksketch,

Is it OK to use Jquery/css in this to hide the other field when not selected like your example? All your other field type don't require Javascript so I wanted to ask? Also would you prefer components/xyz.inc & components/xyz.js or components/xyz.inc & webforms.js?

Thanks
Robert

#12

rmiddle, as you may have noticed, I cheated slightly with the file component, which does contain a little JS, but it's all just added inline. For something more extensive like this (or possibly not, the jquery will probably only be 5-10 lines) we'd probably make select.js file. If you're interested in taking this on, it would definitely be better to integrate this into the existing select component than to make a new one.

#13

quicksketch,

Just to confirm. You would perfer a patch to the existing select box with more options then to create one or two new types correct? I had already started adding two new data types to the code but I am sure it wont be that hard to just add it to the existing select type.

Yea it wont be a lot of Jquery code but some maintainer are very picky about were and how jquery code gets added.

Thanks
Robert

#14

That's right, I'd *much* prefer this were part of the existing select component. Say you had an existing Webform in which you wanted to add the "Other..." option once this is added. You'd have to delete the existing select list, then add a new one, erasing all your existing data in the process. If it's the same type, you can just edit the existing select list, check a box, and be done. It'll be much more friendly to users wanting to toggle this option on and off.

#15

OK. It just becomes fun with the extra data being stored for text. Lets see what I can come up with.

Thanks
Robert

#16

My thought on this was simply that we'd store data the exact same way. We store a list of options entered by the administrator and then the value entered by end-user. If the value entered is the same as one of the options, we map it to the option. Otherwise we assume that it was entered as a an "other" option.

#17

Ok I admit it. I had started working on the form side not the database side. So all select options are stored as text strings. So that makes things a lot easier then I 1st though. From a quick look the most difficult part is going to be the edit submission form and how we handle changes in the form.

Thanks
Robert

#18

Version:5.x-2.3» 5.x-2.4

Subscribing

#19

rmiddle,

I am very interested in the progress of this feature as it is one that is needed for a website I am working on. I was looking into implementing it myself, but noticed that you appear to be making some progress. How are things going? Would you be willing to post what you currently have, even if not working, so that we can get some feedback from quicksketch and figure out what areas still need work? I can help in whatever way is needed. This would be a great feature to add to Webform.

peace,
Matt

#20

I've been looking into how to best implement this feature, as well as thinking about some features (Non-Linear navigation, PDF printing). It seems like there is a need to have webform use it's own theming functions instead of using those from the core form.inc.

This would add a lot more flexibility to the display of webform components and would allow for the addition of new functionality.

Being somewhat new to Drupal module development, I've been trying to figure out how these theme functions work. From what I can tell, adding theming functions to webform entails the following:

  • Add the following functions
    • New theme functions for all components
      • Example: function theme_webform_select($element)
    • New core element theme function
      • function theme_webform_element($element, $value)
  • Add these functions to the appropriate theme hook functions
    • Component example: _webform_theme_select()
      'webform_select' => array(
        'arguments' => array('element' => NULL),
      ),
    • webform.module: webform_theme()
      'webform_element' => array(
        'arguments' => array('element' => NULL, 'value' => NULL),
      ),

Does this approach make sense?

#21

Version:5.x-2.4» 6.x-2.6

So I've got the "other" option basically working for select dropdowns by overriding theme functions. I have not gotten it to work with radios boxes. But I figured I'd post some code and see if anyone has thoughts regarding my approach and advice for making things work with radio buttons.

Some notes:
- There is a new setting to "Allow other option"
- When enabled, this makes your last option the "other" option
- Not sure how this works with option groups... haven't looked into that
- All of the JS and extra html are in the theme_webform_select function
- I have separated out the the code for adding the "other" option html and js, so it can be incorporated into theme_webform_radios, but I have not gotten this theme_radios override function to work properly.

AttachmentSize
select_other.patch 4.49 KB

#22

Title:"Other" option in select lists for text entry» Other
Version:6.x-2.6» 6.x-2.3

#23

Title:Other» "Other" option in select lists for text entry

#24

Forgive me if I'm overlooking something obvious... (Drupal Newbee) :)

I used the "select_other.patch" on the "select.inc" file.

I see the "Allow other" option but when I use it, the Select field disappears from my form. In fact, all Select fields set for dropdown disappear from the form.

Any help would be appreciated. Thanks.

#25

Status:active» needs work

Oh I didn't even realize this issue had a patch. I'm marking code needs work since like Mark says, it's not yet working with radio buttons (and I'd assume the same for checkboxes). timdriedger, I don't think this patch is ready for production use yet.

#26

Subscribing. please make it into a release as soon as possible... i really need this option badly! :)
thank you so much for contributing this excellent module!

#27

I found and fixed an issue related to the "select other" feature not working inside of fieldsets. However I have not been able to look into making this work for checkboxes or radios. I'm guessing that without that, it will not make it into a release, but I'm not sure I'll have time to do it.

peace,
Matt

#28

Perhaps the "Select (or other)" project can help with this:

http://drupal.org/project/select_or_other

#29

Hi,
I was looking for a solution and i found a patch .. I added the patch in select.inc file and its working fine with select (drop down ) not with radios. Hopefully this willhelp you for time being. Replace your select.inc with the patch (select.inc)

cheers
Don

AttachmentSize
patch.zip 5.53 KB

#30

Hi donkasok,
There was select.inc file in my drupal (6.x). So i have created it and added your code in it. But i am not able to see "Other" option in selection list. Is there any permission i need to set?

#31

subscribed

#32

I too am interested in this.

fyi, I tried the patch listed above, but no joy. It gave me the option to include an "other" option that would be the last item. but nothing actually changed in the form itself. ie, no text area for optional user entered text.

#33

I tried using the patch and all of my select fields disappeared.

#34

Hi,
I am really sorry for the late repaly. I was busy with some slide show and LDAP integration testing.

As for webform , once you replace the select .inc with the patch i have given in the above post.

1) Clear your cache from drupal -> perfomance
2) clear your browser cache
3) Go to webform add a component
a) choose type as select
b) Save
c) give optional values, make sure your last optional value is other
eg: your optional values are
Vegetarian
Halal
Others
d) Scroll down , before Advanced settings you can see a check box with Allow other option. Click on the check box.
e) Select list box also
f) Submit

Once you publish your form, Go to your form and choose others from your drop down box .you can see a text box appear next to your select list

cheers,
Don

#35

Hi Don,

This is exactly what I am looking for. I haven't tried the patch yet.

I am a bit skeptical and not sure if this is robust enough for production. And would this patch work for both radio and checkbox? Any chance it will be incorporated to the release soon?

Thanks in advance.

#36

HI,

First of all , I am not the one who developed this patch. After gogoling for hours i found this. But this is working for me with select not with radios. I only know how to create few patches or changes for module. Not good with drupal structure to integrate with the module. If u like this patch you can ask the maintainer to integrate.

with regards,
Don

#37

subscribe

#38

me2 (subscribing)

#39

This is working fine for me. Thanks.

The only thing I wish it did was work with radio boxes and check boxes, in the case that I have a really long bit of text for each item. In those cases, a select list does not work. But for many cases this is great. Many thanks for your work on this!

#40

you need to replace the select inc of yours with mine or compare two files and add the additional lines in my select inc

#41

The initial problem I had was that I replace the old file with the new file and it did not like that. Next I tried opening the old file and pasting in your code. I saved that and everything was happy. Thanks.

#42

Version:6.x-2.3»
Status:needs work» needs review

Attached is a patch that implements an "Other" option using the Select (or other) module. Install the module first, then apply the patch. The patch affects only the file select.inc.

AttachmentSize
webform-select_or_other.patch 3.6 KB

#43

subscribing

#44

The attached patch is updated to work with Select (or Other) 6.x-1.2.

AttachmentSize
webform-select_or_other.patch 2.95 KB

#45

Thanks a lot for the great patch!
It is working like a charm.

I want to add 2 text-fields with the labels populated when selected "others".
Also, is it possible to have one of the text-field produced for "others" option to accept only URLs?

Could you please guide me where to add in this?

Thanks!

#46

I don't understand your first request. Can you give an example?

Your second request can probably be accomplished using form validation.

#47

Thanks Liam!
Form validation made my job easy!!
Well, as far as first query is concerned, I have added the Select (or Other) 6.x-1.2 module with the patch attached in #44.
Now, in my webform, I have got the drop-down list with no. of options including "Others (specify)" with the help of the patch.

When a user selects others, only one text-field appears for the input of "others" option.
Is there any way I can add 2 text-fields with their respective labels.

That is, when user selects others in the drop down, 2 text-fields namely name and URL are generated to be filled.

Select -
name -
url -

I hope I have made my query clear?

Thanks for the help!!

#48

I forgot to add one more thing....
I want to validate the url text field.
I have added the php snippet which does validate but now it is validating even if option other than "others" is selected.

I think, i am confusing you.

I"ll try again -

I have created a select or other drop down list which has got names. One of the option is "others".
Now, if others is selected a new text field appears that I want to be validated for URL.

On adding the php snippet, it is validating even if option "other" is not selected.

Please help!

#49

What you are trying to do is more elaborate than what Select (or Other) allows. It's more a conditional form than a pure "other" (see #254728: Conditional fields). Have a look at the code in Select (or Other). You can probably hack it to make it do what you want.

Note that multiple values can be entered in the "other" box separated by comma (or another character as configured in Select (or Other)).

#50

I've downloaded and implemented Select (or Other). But can't figure out how to apply the patch. Can you direct this poor noob?

#51

@50 Put the patch file in the webform/components directory and run patch < webform-select_or_other_0.patch. You can delete the patch file once you have done this.

#52

Hi Liam!

I've tried your great patch with webform 6.x-2.7 under Drupal 6.13.

But I've 2 issues:

1. I got an error, if i use checkboxes WITHOUT any default, (so the options are: "Multiple"=CHEKED + "Allow Other option"=CHECKED + "Listbox"=UNCHECKED):
warning: Invalid argument supplied for foreach() in /var/www/units/nki/includes/form.inc on line 1200.

2. My "favorite" IE got a wrong focus(?): "other" textfield apper/disappear after the user click another checkbox AFTER the "Other (specify)" checkbox.

I know, you have a 5 minute workaround to these issues ;)

Thanks!
:)

#53

@52

Thanks for the bug report.

Regarding issue #1: Please try the attached patch in place of the previous one. That is, apply the patch to a fresh copy of Webform 6.x-2.7, not on your already patched version.

Regarding issue #2: This bug is in the JavaScript of the Select (or other) module, not in the patch that allows Webform to use Select (or other). I have reported and fixed this issue: #560232: show/hide of input happens at wrong time in IE

Liam

AttachmentSize
webform-select_or_other_1.patch 3.09 KB

#54

Hi Liam!

Works great! Thanks for the rapid help!

km

#55

Thanks guys I'll get that javascript thing fixed soon.
Would it be possible to add webform support into 'select or other' (rather than select or other support in webform) through some form_alters and other hooks? Or is patching webform the only way? Unless you just patch in a module invoke.

#56

Hi,

i am using signup module...do u have any idea how to implement this in "other" option in signup module

#57

@56: I do not know how, but feel free to start an issue under the Select (or other) module, perhaps someone will chime in with a suggestion: http://drupal.org/project/issues/select_or_other?categories=All

#58

@55

Would it be possible to add webform support into 'select or other' (rather than select or other support in webform)

I suppose that can probably be done, but I don't think that the is the best design. Select (or other) implements a single feature in a way that can be used by a variety of modules. It's a good example of the principle of "do one thing well". The module would become way more complex if it tried to patch other modules to use that feature. Ultimately, it seems to me that Select (or other) should be integrated into the Drupal core. I'm sure many modules would benefit from being able to easily add an "other" value to selects.

#59

Thank you for your earlier reply to my post - and please excuse my ignorance - but here goes:

1) When I click on the "webform-select_or_other_1.patch", I get a page with code. Am I to highlight that code, create some kind of file that I then place in my webform/components folder?

2) What do you mean by "run" patch < webform-select_or_other_0.patch?

#60

A patch is a file that consists of a list of differences between one set of files and another. The patch program takes the old file and the patch file, and creates a new file. The patch command that I suggested you run would be available on any Unix/Linux system. You can probably find patch for Windows if you need that. More details and examples are in What is a patch?.

#61

This is the message I get when I run the patch:

[Tami-Whitesides-Computer-10:~] tamiwhit% patch < /Users/tamiwhit/Desktop/websites/Meck\ Promise/sites/all/modules/webform/components/select_or_other_1.patch
missing header for unified diff at line 10 of patch
can't find file to patch at input line 10
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540
|{\fonttbl\f0\fmodern\fcharset0 Courier;}
|{\colortbl;\red255\green255\blue255;}
|\margl1440\margr1440\vieww9000\viewh8400\viewkind0
|\deftab720
|\pard\pardeftab720\ql\qnatural
|
|\f0\fs24 \cf0 --- webform/components/select.inc 2009-03-04 00:05:11.000000000 -0500\
|+++ webform/components/select.inc 2009-08-18 13:09:53.000000000 -0400\
--------------------------
File to patch:

...so what is my next step?

#62

Yeah it's a command you type in linux, and a lot of documentation on this site regarding linux commands doesn't make that very clear, and even if it mentions so, it's done in a vocabulary only existing linux users would pick up on.

#63

Please continue the conversation about applying patches in Applying patches in Mac OS X.

#64

Thanks Liam

I used the patch. It works well in form display, however the answer in the textfield of other option was not saved in database. Hence ,it also could not be reviewed or re-edited. Have the patch implemented these functions? Or the patch just prvoide displaying well until now?

#65

The patch works for me, including saving values to the database.

#66

Can this patch be added to the module code next version? Thanks!

#67

Hello Liam

I found that saving values may not work when checking "Multiple" and "Allow Other option" in setting. I think the bug could be founnd in function _webform_submit_select. Because other option key value was not stored in webform_component table, in this function, submitted value could not map to saved options. Therefore, I suggest the other option should also be stored in the extra field of webform_component table with key "other".

#68

Yes, I am getting this too. My form doesn't use both "multiple" and "other" in the same component, so I didn't notice it. Do you have a patch?

Are you using a save draft patch? I am finding that when select-or-other is combined with this save-draft patch, the select-or-other values are not saved when saving a draft, but they are saved on final form submission (but still not when "multiple" and "other" are used together).

#69

This is workaround patch for fresh copy of Webform 6.x-2.7. It is based on the patch provided by Liam and just several lines was modified. Now, answers were stored when checking both "multiple" and "other".

However, I found another problem now. In multi-pages form, check both "multiple" and "other". You could find that the answer is not displayed correctly when clicking 'Previous Page' button to re-check answer. They always just show the default options not those options I haved entered in previous page.

Could anyone help me solve it?

AttachmentSize
webform-select_or_other_2.patch 3.82 KB

#70

Thanks for the patch, its exactly what I need, however...

Not sure whats happening here but on my version of 6.x-2.7 the patch is not matching the version of select.inc file.

There is a function webform_expand_checkboxes that doesn't get called at all. Can you confirm that this patch is for 6.x-2.7?

Thanks a lot!

Adam

#71

Please ignore my above comment as I now have the patch working. However I did find an issue with it despite the one mentioned. While in the analysis and table the results do appear, in the download they do not.

For us this is quite a killer blow as the excel/csv download is vital for the full data analysis of the webform.

Is there any easy fix for this?

Also, the code seems to remove the description field, which is also not ideal.

For info, all of the fields I'm using the "Other" option on, are all "Multiple fields" with added validation and are not drop downs. (so checkboxes).

Thanks,

Adam

#72

Actually we would be able to pay a bounty on the above two features if someone can provide a patch in the next 48 hours. I'm quite sure it will be an easy patch and we would give $100, but we need it fast. Thanks! Adam

#73

Status:needs review» needs work

This patch needs to be updated for the 3.x version, as no new features are being added to 2.x. I think there are few scenarios that this patch still needs to accommodate (such as the analysis of results).

#74

Status:needs work» fixed

This patch builds on Liam Morland's excellent patch and adds the following functionality:

- Added module_exists() checks so that things don't break if the module is not available.
- Added support for CSV, e-mail, and submission display of "Other" options.
- Probably the most interesting: Added support for viewing the list of "Other" options entered underneath the Analysis section. So you'll see something like "Other... | 29 (view)". Where 29 is the number of other values entered and may be viewed individually by clicking the "view" link.

This set of changes also gives me a lot of ideas for how to implement #282885: Combining webform with charts, since I realized that most charting people want to build is actually just a chart of the content within the Analysis tab. Anyway, that's something else.

I've committed this patch. Thanks a lot Liam and shadowx for your help putting these patches together!

AttachmentSize
webform_select_or_other.patch 16.79 KB

#75

Have all the fixes and patches been incorporated into the current versions available for download of,
Webform and Select-or-Other, modules? Must a patch still be made?
I have downloaded both Webform and Select-or-Other, and the Other is not opening a text input box.

#76

Yes everything is all committed. You have to use the 3.x version of the module.

#77

In the list of choices using radio buttons, the "other" does not open a text entry box.
I am using Webform 6.x-2.9
select-or-other 6.x-1.6

Quicksketch, I know you said I have to use the 3.x version of the module, but it is not available for download on the Webform module page. So where do I get it?

Thanks,

#78

Click "View all releases" from the project page and find the 3.x version.

#79

Is there a solution to this in Drupal 5?

#80

No, all new features are being added to the 3.x version, which is targeted for Drupal 6 and Drupal 7. All support for Drupal 5 will be dropped within the next 2 months.

#81

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#82

Version:» 6.x-3.0-beta5

This is beautiful. Thanks to everyone who helped on this. I've just downloaded select_or_other module and it's working great with Webform 3.x.

#83

Here is the patched version of the webform file (6.x-2.10). See #53.

AttachmentSize
select.inc_.zip 4.71 KB

#84

Version:6.x-3.0-beta5» 7.x-3.0-beta2

Does anyone know if this will also work for check boxes when managing fields when creating content?

The calendar I'm working with has basically 6 locations that are used over and over again - So I'd like those to be a in a check box list. But I also wanted an option to type in a new location if its not one of the main 6.

#85

Apparently what I'm looking for is conditional fields. sorry to interrupt.

#86

Anyone looking here might be helped by looking here: http://drupal.org/project/select_or_other

nobody click here