I think, it doesn't really make a lot of sense, to say, each multiple field type has 3 fields, so the attached patch would make the number of multiple fields adjustable (this patch only sets this for the text.module at the moment)

CommentFileSizeAuthor
#33 text.module.txt14.35 KBtormu
text_multiple.patch1.51 KBmh86

Comments

dodorama’s picture

I like this. go testing ASAP.

fago’s picture

Nice little feature.

Patch applies clean to cck head and with offset to cck 4.7 and does its job :)

criz’s picture

cool, would be useful for other multiple fieldtypes too...

marcoBauli’s picture

howdy,

you think this would be somehow easily implementable for the imagefield as well?

(when i asked this feature for imagefield i was told it was a task of core cck, not of single field type)

thx

mh86’s picture

yes, this feature is also possible for other field types! If there is the need for, it would be better to put this into the cck core and then it would be available for all fields!

fago’s picture

but what if a select widget is used? in this case the field doesn't suit.

dodorama’s picture

True. But select list doesn't allow multiple values whatever you apply this patch or not. As I posted here this is a kind of bug (or usability issue).

karens’s picture

One approach to this would be to put this in the widget rather than the field. That way it only is an option if the optionwidgets widget is not used. Irregardless of any bugs in optionwidgets, you can't control how many items are selected in a multiple select list, so as fago says, it doesn't make sense in that situation.

I'd prefer to find something that could be done generically in the content module instead of altering each individual field module to do this, but this may not make sense since it depends on things like whether a select list is being used.

karens’s picture

As I think about this more, I realize that we also need to think about where the 'multiple' option is displayed. Maybe both the multiple checkbox and an option for the number of multiple fields belongs in the widget rather than the field, since they seem to go together, i.e. optionwidgets is going to use the multiple select checkbox to control whether multiple select fields or checkboxes are offered and won't need to know how many option should be allowed, while a multiple option on a plain taxtfield should perhaps allow you to choose the number of items to create and maybe a different label for each one. An example would be a phone number field where you might want to show a home and work number as a multiple value textfield.

blockedmind’s picture

Is there any patch for Drupal 5 does the same thing? This is inadaptable to version 5.

seanberto’s picture

I certainly don't have the skills to do this, but what about using javascript to hide multiple fields - as the civicrm module does. You could let the Drupal admin set a max # of fields, but then hide them on the add/edit form with a button to display X number of fields.

Better yet, what if ajax was used to create additional fields from the edit form?

I'm a newbie - so this might all be a pipedream.

But I really like where this is going!

rickvug’s picture

Just bumping this and adding my support. In http://drupal.org/node/103544 I state my case as to why. Now comes the "how" part. I makes sense to add this support in a universal fashion not just on a case by case basis.

karens’s picture

Marked http://drupal.org/node/124075 as duplicate.

macm’s picture

subscribing. Nice idea.

moshe weitzman’s picture

would be useful ... subscribing

ray007’s picture

subscribing

profix898’s picture

Marked http://drupal.org/node/139657 as duplicate.

xamount’s picture

subscribing

dami’s picture

I can think of a few use cases:

1. Fixed number of multivalue fields:
An easy (may not so good) hack may be change field['multiple'] to textfield instead of checkbox, then use it to configure how many addition instances/multivalues are needed for this field. (0 means 'not multiple).

2. Expand on the fly:
It'd also be great to have dynamic expandable field, like what ahah_form does. Maybe we can reuse some of the code there or simply build it upon ahah_forms ?

3. Number of multivalue field depends on another CCK field value.
One use case maybe if we want to record a soccer game. We'll have a CCK number fields (interger) for each team's total score X. Then we will have another CCK field (X instances) for specific info of each score/goal.

ray007’s picture

@dami

ad 1) and a special value like -1 for 'unbounded'? we should also think about something to specify a minimum and maximum

ad 2) have only tested ahah_forms very lightly, but sounds good to me

ad 3) sounds like yet another good place to use the token module

StevenSokulski’s picture

Subscribing

webchick’s picture

Sub.

profix898’s picture

For Drupal 6 this issue could also be solved using AHAH to add more fields if requested by the user. Similar to http://drupal.org/node/155870 which adds additional choices to poll.module form ...

bsuttis’s picture

Any one got this patch working in 5.1?

I applied it manually, and I can choose how many fields I want, and add and remove values in the fields without issue.

However, if my fields value is set at 5 and I fill in all 5, submit, and re-edit the node, I see that a new field has been added (making 6 fields shown, with the bottom 2 empty), and the 5th field has had its value removed.

I only noticed a couple differences in the actual patching of the 5.1 version, so I didn't think there'd be any problem, but there appears to be a couple issues. I tried the patching a couple times and get the same results. Just interested if anyone has got it working in 5.1, this is a really useful option.

gubilla’s picture

sub.

Caleb G2’s picture

subscribing. I looked around for about an hour before finding this thread. Was surprised to find that this isn't a feature of cck and/or a current contrib...

tonyn’s picture

Sub.

rickvug’s picture

With the AHAH form api stuff going into Drupal 6 core hopefully this will be built right in. For more information on what the framework is see the Drupal 4.7 module: http://drupal.org/project/ahah_forms.

rapsli’s picture

When do you guys think it will be part of cck text. I really need this function:

2. Expand on the fly:
It'd also be great to have dynamic expandable field, like what ahah_form does. Maybe we can reuse some of the code there or simply build it upon ahah_forms ?

Anybody working on it? The patch only gives me the permission to give a fixed number of text fields, plus with 5.2 there's a bug, when editing a node.

yched’s picture

This will be much easier to do with the (currently in progress) CCK for D6, and won't happen in 5 branch.

benwei’s picture

subscribing.

tormu’s picture

The Link fieldtype has this function implemented. When I check the "multiple values" from the field with type "link", it will have "More Links"-button under the second field. Pressing the button makes a new line come up without submitting the form. Couldn't this be brought fairly easily to Text field too?

tormu’s picture

StatusFileSize
new14.35 KB

Since I'd really be needing this feature I got a bit into it and tried importing the functionality from the link.module.
I got it working but I'm 99.892% sure there are many things that needs to be taken into account and that this will fok them up.. But maybe someone from the text.module team could have the time to look into it. Attached is the current text.module I have, which uses the link.js file from the link module and contains roughly copy-pasted and altered stuff from the link.module.

Modifications
- new stuff at the beginning of text_widget() [also notice the + 2 changed to + 0 in row 320] and
- new function _text_widget_form()

karens’s picture

Status: Needs review » Fixed

This feature (implemented differently than in this patch) is now in HEAD for the D6 version of CCK. In that version you can now either select that you want a specific number of multiple fields, or that you want unlimited multiples. If you select unlimited multiples, you get a nice AHAH add more button to add as many fields as you like.

Marking fixed because this is now in HEAD. It would be quite difficult and messy to get this working in D5, so it probably won't be back-ported.

bsuttis’s picture

I'm getting a 'warning: Cannot use a scalar value as an array in ...sites\all\modules\cck\content.module on line 587.' error when submitting a node using the updated code in #33, the values in the added fields aren't saved either -- any ideas why?

scottrigby’s picture

subscribe - thx
(in particular, I'd be interested in further developments on #33 patch for Drupal 5.3)

scottrigby’s picture

Status: Fixed » Needs work

@#33

I'd like to test, but am I dong this right?

(from text.info: version = "5.x-1.6-1")

- I disabled CCK Text in Administer > Modules
- replaced text.module with the one downloaded from #33
- enabled CCK Text in Admin > Mods again

- I opened a listing which I hadn't previously added anything in the text fields I wanted to test
- Added some info
- Here's the error:



    * user warning: Duplicate entry '24-0' for key 1 query: INSERT INTO content_field_days (field_days_value, vid, nid, delta) VALUES ('h', 24, 24, 0) in (path)/includes/database.mysql.inc on line 172.
    * user warning: Duplicate entry '24-0' for key 1 query: INSERT INTO content_field_days (field_days_value, vid, nid, delta) VALUES ('', 24, 24, 0) in (path)/includes/database.mysql.inc on line 172.
    * user warning: Duplicate entry '24-0' for key 1 query: INSERT INTO content_field_days (field_days_value, vid, nid, delta) VALUES ('M', 24, 24, 0) in (path)/includes/database.mysql.inc on line 172.
    * user warning: Duplicate entry '24-0' for key 1 query: INSERT INTO content_field_hours (field_hours_value, vid, nid, delta) VALUES ('h', 24, 24, 0) in (path)/includes/database.mysql.inc on line 172.
    * user warning: Duplicate entry '24-0' for key 1 query: INSERT INTO content_field_hours (field_hours_value, vid, nid, delta) VALUES ('', 24, 24, 0) in (path)/includes/database.mysql.inc on line 172.
    * user warning: Duplicate entry '24-0' for key 1 query: INSERT INTO content_field_hours (field_hours_value, vid, nid, delta) VALUES ('M', 24, 24, 0) in (path)/includes/database.mysql.inc on line 172.
    * warning: Cannot use a scalar value as an array in (path)/modules/cck/content.module on line 587.
    * warning: Cannot use a scalar value as an array in (path)/modules/cck/content.module on line 587.

- It didn't add a new field.
- Also, it refreshed and jumped back to the top of the page (my thought was - this isn't very ajaxy)

Let me know if I can modiy anything to help test - this would be a great feature if we can get it to work --
Scott

karens’s picture

Status: Needs work » Fixed

This issue is about adding this feature to HEAD, which has been done. And both yched and I have posted to say that it would not be easy to do this in 5.x so it is not likely to get back-ported. So this issue is fixed and done.

If people want to play around with a method of getting this working reliably for all possible (or selected) field types in 5.x (a difficult task), I suggest you collaborate by creating an issue in the CCK group on groups.drupal.org. Just keep in mind that it is very likely that your work won't get into an 'official' version of CCK, at least unless someone comes up with a simple, easily maintainable method that has been proven to work even on complex fields. That is to say, getting it to work on the text module is only the very tip of the iceberg.

I'm not trying to be negative on the subject, it's a feature I'd like to see, too. But none of the CCK maintainers has time to create, debug, or maintain this, unless someone else does all the work for us :)

scottrigby’s picture

Ok - I was just testing the patch. Apologies for getting off track here.

But -- since D6 isn't production ready yet, and this would be a very helpful feature that I saw people here are already working on -- I'd like some way of finding out about any new developments.

So -- if anyone reading this thread finds out any new developments about this feature -- I'd be appreciative if you'd post a link here as a follow-up.

Thanks, & good luck this feature in HEAD

Scott

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

icecreamyou’s picture

Status: Closed (fixed) » Active

Is there any reason this couldn't be implemented in 5.x the following way:

Instead of adding new fields in an AJAX-y interface, just add new fields when the Preview button is clicked? That would be exponentially better than clicking Submit and then Edit each time, and it would work just like the Poll module currently does.

Check out hook_form() in the Poll module in D5.7, which uses this code to do what I've described above (at least, I think it's this - I'm no programmer):

  if (isset($form_values)) {
    $choices = $form_values['choices'];
    if ($form_values['morechoices']) {
      $choices *= 2;
    }

'morechoices' comes from this:

  $form['choice']['morechoices'] = array(
    '#type' => 'checkbox',
    '#parents' => array('morechoices'),
    '#title' => t('Need more choices'),
    '#value' => 0,
    '#description' => t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."),
    '#weight' => 1,
  );

Thoughts? It seems like this should be easily doable.

yched’s picture

Version: 6.x-1.x-dev » 5.x-1.x-dev

Changing version, then.
Bottomline is : in CCK D5, such a solution would have to be implemented separately by all field modules. I'm personnally not planning on doing any work on this, and, as Karen stated in #38, a patch pushing this kind of feature in the D5 branch would have to be clean and easily maitainable to be considered for committing.

Rosamunda’s picture

Suscribing

janwari’s picture

Subscribing

karens’s picture

Status: Active » Closed (won't fix)

A very old feature request for D5, won't do anything with this now.