I tried to find some discussion of this functionality, but could not make this happen with either Webform or by modifying the webform with CCK (the custom CCK shows up as a field on the webform creation page, not as something to add as a component that the webform user submits). So is there a way to have multiple text fields become available to the person who submits a webform? Add another "field" on submission of the webform?

CommentFileSizeAuthor
#62 webform_expandable_fieldset.zip12.17 KBapatrinos
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Bartezz’s picture

Ever succeeded in doing so?

Cheers

bomarmonk’s picture

I haven't tried with the latest versions of Webform, but I have never successfully done this.

Bartezz’s picture

alright thanx!

Bartezz’s picture

Version: 5.x-2.3 »

Quicksketch,

I came here to see if there as any news on this but I guess there isn't.

Isn't the feature requested possible at all? Or is it something you're not willing to look into?
It would be brilliant to have an 'add another item' option for an input or maybe even a fieldset with multiple inputs inside it.

I guess backendwise it would be harder to fix this as to serialize the data for such an input would render many functions useless but I would love to see this feature so much. And others with me (marked some posts as duplicate).

What's your opinion Quicksketch?

Cheers

sfks’s picture

I think it would be great too.

Regards.

Boland’s picture

Is there any news on this subject? I have searched the whole internet I think, but can't find any solution... Anyone??

quicksketch’s picture

No, there is no progress on this subject. The ability to support multiple values requires a tremendous amount of re-architecting, including changes to the way CSVs are generated, analysis, the database structure, and the UI (both for administrators and users). I wouldn't expect this feature to be added any time soon.

Boland’s picture

Is there another solution, in another module? I cannot find such a thing like this in a module for Drupal :(

Bartezz’s picture

The only option I can think of is to use some jquery.

- First you create, let's say, 10 input fields in webform.
- You hide input #2 thru #10 by css
- Insert a button 'add another' with jquery
- And then .show() #2 thru #10 when one clicks 'add another'

Downside is that you have quite a bit of setting up to do in webform and that it's not really unlimited. It's basically limited by you webform setup stamina :)

Cheers

Boland’s picture

Thought of that, but it ain't unlimited indeed :)
With content type fields this is possible, but then every webform submission will become a node. Perhaps that will be the better solution, because it should be really unlimited.

Bartezz’s picture

CCK fields would be your only option if it really has to be unlimited... or creating a custom module.
Why is it a problem that every submission will become a node?

Cheers

Boland’s picture

Thought that could be a problem :)
Trying using nodes and CCK now!

Thanks for replying! Will post here if i'm ready!

quicksketch’s picture

rreck’s picture

Version: » 6.x-2.9

I need this functionality too, but even a little more complicated. Imagine someone is entering CDs and each CD has a title, artist and songs. I would like them to be able to add another CD or add another song. Any ideas?

quicksketch’s picture

Version: 6.x-2.9 » 6.x-3.x-dev

Moving this back into the 3.x branch (issues all lost lost their 3.x versions when I branched for Drupal 7). The trouble with anything like this is that there is a lot more to Webform than just collecting the information. We need to update the analysis, table display, CSV downloads, and other areas to support such things. In Webform 3, I'd suggest making your own component. Either way this would require a significant amount of effort.

joeybernal’s picture

This would be fantastic for many reasons!

pixel8r’s picture

Would you do it for a Klondike bar?

All jokes aside, that would be a wonderful feature to have. We will keep the hope alive...

westie’s picture

subscribing

cpotter’s picture

+1 subscribing

texas-bronius’s picture

I'll weigh in here to say that #9 @Bartezz above had a clever solution. Depending on your needs, my planned a-hack on this for my simple "order system" is to dynamically build a row of non-webform form fields (partno, desc?, qty, Add Row) which, upon submission of the form, concatenates these form fields' values into a hidden webform textarea: not beautiful, but gets it done in my use case.

If you're interested, stay tuned! It's just crazy enough, it might work..

-Bronius

d.holmen@gmail.com’s picture

Subscribing

jazzitup’s picture

Subscribing

rbrownell’s picture

Subscribe.

rbrownell’s picture

rbrownell’s picture

A multigroup function similar to that of CCK's multigroup would be ideal. I need individuals to be able to submit table - like data via email and not necessairly have the data stored on the server the way CCK does.

I am including this apparently redundant post because the word multigroup does not appear in it at all and therefore when seaching the issue queue for this issue it did not appear in the search results.

dharper’s picture

Subscribing.
PS L O V E webform!

mallezie’s picture

subscribe

sourcesoft’s picture

really need it at this point
Subscribing

Bartezz’s picture

Guess that 'at this point' there still is no solution other than the ones given above.
Don't think quicksketch is likely to develop such a feature because we 'need it', it's rather complicated as described above!

Cheers

Darkplek’s picture

If anybody knows how to achieve this functionality, either via webforms, or another module, or by writing it from scratch, I'd be very, VERY grateful to hear it. I'd love this functionality to be implemented, but since it's not, at least currently, I'm needing suggestions for alternate solutions.

For example, any information on how a solution as described in #20 could be made would be of great use.

Bartezz’s picture

Darkplek,

Quick reply;
- add a hidden field to your webform
- use hook_form_alter in a custom module to add the non-webform field(s) to the webform
- use drupal_add_js in a custom module to add jquery magic to the webform
- through that jquery the user can clone the non-webform fields as many times as he/she needs it
- bind a function to the webform submit button that reads all the data from the cloned non-webform fields and inserts this list of data into the hidden webform field

Cheers

span’s picture

Thanks for your input Bartezz, I'm also looking to do this. I will post back my code if any of it can be used when I'm finished.

span’s picture

I had 10 fields in the fieldset that I need to be able to show to the user on demand.

Heres my javascript that i added to a file to add fields and then take their data and put it in a textarea which is set to display none. This solution turned out uglier than I had hoped and made it very hard to get at the data submitted without writing som PHP to go with it.

In the end I went with a solution where I added 20 fieldgroups to the webform itself within a wrapper fieldset to be able to target the children, all fieldsets containing my 10 fields, and then I used the second script to hide them all except the first one, add a button to display another fieldset etc. Since the adding and hiding is all done with scripting, all fields will be displayed to a user without JavaScript enabled which is a good thing.

// Removed first script, it was to ugly

And I ended up with:

// This is cleaner although not clean
(function ($) {
  Drupal.behaviors.[THEMENAME] = {
    attach: function(context, settings) {
     var i = 0;
     $('#webform-component-objectwrapper'). // Get the wrapper, change the ID to suit your needs
      append('<button id="add-object-button">Lägg till lägenhet</button>'). // Add button, change text to suit your needs
      find('fieldset:not(:first)'). // Hide all but first fieldset
      hide();
      
      $('#add-object-button').click(function() { // When button is clicked and it's not the last fieldset out of 20 to be displayed
        if(i < 20) {
          $('#webform-component-objectwrapper fieldset:not(:visible):first').fadeIn(); // Show the fieldset, remember to change the ID
          if(i == 18) {
            $(this).hide(); // Hide the button
          }
        }
        i++;
        return false; // Prevent submission
      });
      
    }
  };
})(jQuery);
Bartezz’s picture

@span; Ah this a solution based on my comment in #9, nice. Thanx for sharing, hope it helps others.
Let's hope Darkplek works out a solution based on #31 and shares it as well :)

Cheers

Dubs’s picture

I've added the code fromn #33 as suggested (using drupal_add_js and referring a file). However, I get "This is not a function" from Firebug when trying to do so and things don't work as expected. [themename] was changed to the name of my theme too.

mcpuddin’s picture

I highly recommend the in-dev version of the module field collection, you can do all you want to above using nodes. Check it out, http://drupal.org/project/field_collection

TechNikh’s picture

+1 subscribing..

texas-bronius’s picture

I see I neglected to followup with my own jquery hack proposed in #20 above. It ended up being really inelegant, and the results are, after all, crammed into a TEXT fields in the database with built-in delimiters to boot. What is this, a backward IBM Universe Multivalue DB? Yikes-- no thanks.

Sorry not to be of any more help here.. I can see quicksketch's point and that webform is not architected for this. So I wanted to further the discussion of, potentially, a non-webform solution: has anyone taken this to g.d.o yet? I would like to talk about "anonymous can post a cck/entity and then any number of nodereferenced subitems." We would obviously miss out on all the cool webform survey results, but Views could be whipped together, right?

ktleow’s picture

Subscribe

This feature would make Webform uberawesome.

kranklin’s picture

@span Thanks for your code however it caused an error when I used it. My fix was to remove the object with the 'attach' function and assign the function directly to Drupal.behaviors.["THEMENAME"]. Here is my code with some changes:

  • Edit: Allows you to specify how many should be shown initially
  • You don't have to provide the number of fieldsets. It performs the count.
  • Adds protection against nested fieldsets, so even if you have "fieldset > fieldset", only the top level of fieldsets will be affected
  • The function can easily be reused on more than one repeatable component
(function ($) {

	Drupal.behaviors['YOURTHEME'] = function(context, settings) {

		function fieldsetRepeater(container, fieldsetSelecter, addBtnTxt, numberFirstShown) {
			var addBtn = $('<input type="button" />').val(addBtnTxt).click(function() {
				var hiddenFieldsets = fieldsets.not(':visible');
				
				hiddenFieldsets.filter(':first').fadeIn();
				if(hiddenFieldsets .size() < 2) {
					addBtn.hide();
				}
			});

			var fieldsets = container.find(fieldsetSelecter)
				.not(container.find(fieldsetSelecter+' '+fieldsetSelecter))
				.hide();
			
			fieldsets.filter(':last').after($('<div/>').append(addBtn))
			
			for( var i = 0; i < numberFirstShown; i++ ) {
				addBtn.click();
			}
		}
		
		//Shows one apple initially
		fieldsetRepeater($('#webform-component-apples'), 'fieldset', "Add an Apple", 1);

		//Shows no oranges initially. Button must be clicked.
		fieldsetRepeater($('#webform-component-oranges'), 'fieldset', "Add an Orange", 0); 

	};

})(jQuery);
achrelam’s picture

Hello,

The button to append a new fieldset doesn't appear. The Js script is loaded, but there is no action on my container #webform-component-MINE.

Do we have to create e.g 10 fieldsets, hide all except the first one ?

Thx a lot.

ain’s picture

Should be standard functionality in Webform. Subscribing.

quicksketch’s picture

@ain: Use the "Follow" link at the top of the page instead of subscribing.

john.money’s picture

+1 for the patch approach in #40.

Note for anyone implementing, I got this to work perfectly with a selector like this:

fieldsetRepeater($('#webform-client-form-18'), '.webform-component-fieldset', "Add another", 1);
shimba’s picture

sorry John but I am new at this. kindly tell me where to insert the code.

Pongolyn’s picture

Subscribing

john.money’s picture

Shimba, you will need to create a new JS file like in #40 and then include it on the page(s) you want. There are a few different ways to do this (via custom module, your theme, etc) that are really beyond the scope of this thread. If you are really stuck, email me with your drupal version, the node ID for the webform, and I'll whip you up a small module later this week.

john.money’s picture

Got a few emails about this, created a small module Webform Add More based on approach and code provided by span and kranklin. All credit goes to them.

quicksketch’s picture

Nice one John Money!

Bartezz’s picture

Nice work John! And thanx for the credits :p hehehe

Cheers

john.money’s picture

Ouch! Sorry I missed you in credits Bartezz. Fixing on project page.

Bartezz’s picture

Cheers :)

mohann2009’s picture

Version: 6.x-3.x-dev » 7.x-3.8

What i'm missing? installed smoothly on my system. Add more option is available in the fieldset but i can't find add more button when webform is saved. badly needed this feature.

blauerberg’s picture

Subscribing

droprocker’s picture

Version: 7.x-3.8 » 6.x-2.1
Category: feature » support

Same here like at post #53.

I'm working on a Drupal 6.26 installation and the 6.x-1.03 Version of the module. Please help! I really need this functionality. I would appreciate any help...

rbrownell’s picture

Category: support » feature

Changing back to feature request... this can't be a support request because this feature does not exist yet.

rbrownell’s picture

Category: feature » support
Status: Active » Fixed

Changing back to support request...

@missingdot check out this module http://drupal.org/project/webform_addmore

Closing this because it appears to be resolved... Any issues with functionality of the 'solution' module should be posted directly to the issue queue for the webform_addmore module.

mallezie’s picture

Status: Fixed » Postponed

I see that the functionality of webform_addmore could be used.
But this is actually a hack.
Shouldn't we keep this issuu open to make a true 'add another' functionality like field_collection does.
Add more is a nice temporary solution, but is actually 'hide some fields'.
Full respect to John Money, span and kranklin. Nice work.

Real 'add another functionality is a huge undertaking', but i wouldn't call this issuu closed. Marking to postponed on #118984: Field API based rewrite of webform module
Hoping that one day we truly could get this done. If you think this is fixed, you can set this back. But wanted to point out my concern.

lsolesen’s picture

Category: support » feature
rbrownell’s picture

I would have to agree with you. I must admit I didn't thoroughly check out the other module.

-R

jmrivero’s picture

Im wondering if its possible that instead of create 20 fields and hide them, create the fields dynamically on request to add another, even if it means shove it in the database as another field of the form each time the current amount of fields is not enough for the user filling the form, then for another user, use the same hide functionality as used now.

So the steps could be:
- user fills the field
- user clicks "Add more" button
- call the function to add a new component to the form via ajax ( punch the new component in the webform database )
- retrieve the new component and alter the form
- repeat until done

And for another user:
- hide all the components but one
- user fills the field
- if more needed, show another from those saved in a previous submission
- if not enough components call the function to add a new component ( punch again )
- retrieve new component and alter form
- repeat until done

In the end, as the new components are inserted in the webform there should be no need to modify the reports thought.
So my doubt is if it is possible to "Punch" new components like this in webform.

apatrinos’s picture

I've been working on an implementation of an 'expandable' fieldset component for drupal 7 and webform 3.x. The module essentially tries to piggy-back on an existing webform by dynamically creating an 'Add Another' and 'Remove Last' buttons to which AJAX callbacks are attached, which create a copy of the existing fieldset's original children giving them new field keys etc. The extra values inputed by the user are saved in module-specific table. I've gotten it to work more-or-less, but there are some important drawbacks that must be addressed:

1. When re-editing an existing field the new values are not retained.
2. After re-loading an existing submission for editing, the 'add another' functionality breaks, field values become confused.

Perhaps someone more experienced with the form API and/or webform might want to take a look...

cmspagnola’s picture

Version: 6.x-2.1 » 7.x-3.18

I tried installing your module (I have version 3.18 of webform), but it says I don't have QA_Utility...but I can't seem to find any module with this description. I'm not incredibly familiar with drupal, and so this might be a stupid question...but what is QA_Utility and how do I get it?

shakeeltariq’s picture

Subscribing

Liam Morland’s picture

Version: 7.x-3.18 » 7.x-4.x-dev
DrupalDan’s picture

subscribing

cconant’s picture

Patrinos, I also tried installing your module and ran into the same issue. I am also new to Drupal, and couldn't find the QA_utility module anywhere. Can anyone help out with this?

lunk rat’s picture

Multi-value, grouped, 'compound fields' with an "Add another item" button can be achieved with Drupal 7 + EntityForms + Field Collection:

http://drupal.org/project/field_collection
http://drupal.org/project/entityform

I opted for this rather than trying to get Webform to work.

mdburrell’s picture

see simple solution to add more fields to a webform.

oncreative’s picture

@lunk_rat #68 - Any chance you could expand on your solution a bit more?

I've created an entity form and a fieldset with a field in it but can't see how get it to dynamically add more fields in the fieldset via an Add Another button. Or how to add a button at all for that matter. I haven't discovered what you mean by "Multi-value, grouped, 'compound fields' ". All I need is for someone to add any number of additional text fields.

lunk rat’s picture

@oncreative: On your field, do you have the "Number of values" set to "Unlimited"?

mmomin’s picture

Issue summary: View changes

Webform Matrix Component module can be helpful to those who are looking for "add more" functionality for webform component.

DanChadwick’s picture

Status: Postponed » Closed (won't fix)

See the Webform Multiple project or Webform Matrix Component. If there is an effort to incorporate "multiples" of each component type into webform itself, that would be where it would most likely come from one of these modules.

Please re-open with a patch if you have a comprehensive solution that is ready to be incorporated into the latest development branch, currently 7.x-4.x.

gaurav@mapmytalent.in’s picture

enhancing number of field in drupal 7 webform

gaurav@mapmytalent.in’s picture

I am not able to add field in drupal webform