I have multiple fields that have multiple values and I would like the ability to put a separator between them. For example here is what is happening right now.
Field: What are your favorite colors? [X]blue []green [X]red []yellow
Output: Favorite colors: blue green
What I would like the output to be is: Favorite colors: blue, green
Maybe there is already a good easy way to do this (I've already tried to look all over the place to no avail) and if somebody could tell me what it is that would be awesome but I really think there should be a place under "Group multiple values" where you can enter a separator.
Thanks!
Comments
Comment #1
dawehnerSo you have two fields. You can use the "rewrite output of this field" setting to do it.
In the second field use this rewrite pattern:
In the first field use this rewrite pattern:
Comment #2
deggertsen CreditAttribution: deggertsen commentedI'm aware of how to do that. But the problem is that it's only one field with multiple values that I'm using. So I'm wondering if there is a way to rewrite the output of [field1]'s multiple values. Because field 1 contains all of the values (i.e. blue green red and yellow). Does that make sense? If each value was contained in separate field it would be easy to comma separate them but since that is not the case what do I do? I believe there is a way to create a tpl.php file to change the output of a specific field but I don't really understand how I could use that method to add separators. And it would just be nice to have an option under "Group multiple values" that allows you to insert a separator.
Comment #3
ezeedub CreditAttribution: ezeedub commentedI'd like to see this improvment also. I was surprised that it wasn't there when I first encountered this feature, and then I forgot about it.
Using n fields is not practical. You'd have to set n "starting from" offsets for fields with n values.
Anyway, selecting the same field multiple times and rewriting does not solve for fields that allow unlimited values.
Comment #4
jay-dee-ess CreditAttribution: jay-dee-ess commentedsubscribing
Comment #5
jcarlson34 CreditAttribution: jcarlson34 commentedNot sure but if you are able to find a way to get the values into separate fields, this http://drupal.org/node/854002 might help you hide the commas for the ones that aren't active.
Comment #6
merlinofchaos CreditAttribution: merlinofchaos commentedIf you're talking about a CCK field, it's up to CCK to provide the separator in the handler. Most multi-value fields for core, Views already provides this functionality.
Comment #7
roball CreditAttribution: roball commentedYou can do this by copying "views-view-field.tpl.php" into your theme's directory, under a name the view will recognize it selectively. Put the following code in it:
print preg_replace('/<\/div><div[^>]+>/i', ', ', $output);
Comment #8
deggertsen CreditAttribution: deggertsen commentedThank you roball. That is very helpful!
Comment #9
GRRaka CreditAttribution: GRRaka commentedI have the same requirements, but my data is being exported to a spreadsheet.
Using Group multiple values results in "redgreenblue".
How can I make this look like "red,green,blue"?
Comment #10
GRRaka CreditAttribution: GRRaka commented#7 worked for me.
Thanks roball.
Comment #11
baisongI had the same problem, creating a downloadable CSV feed view for a view, all my data was being concatenated with no separator -- I believe if it wasn't a plain-text view handler, there would be markup to separate the values.
As a solution, I used a customfield PHP snippet to generate arrays and implode them in the view. Probably slow for production sites, but for data extraction, it seemed sufficiently fast. Just install the customfield module, add a customfield PHP snippet (make sure you have permission to evaluate the PHP input format) and then paste these snippets in (along with the unseparated multivalued fields, exclude to hide them) to generate the separated list.
This is for text/number values
This is for node references (I needed the title from the node id (NID)
Comment #12
ohthehugemanatee CreditAttribution: ohthehugemanatee commented#7 is a great, elegant way to handle the problem. Thanks!
Comment #13
aubjr_drupal CreditAttribution: aubjr_drupal commentedThanks for #7, roball! Elegant and simple solution...
Comment #14
Daniel Wentsch CreditAttribution: Daniel Wentsch commentedYepp, thanks roball, now using #7, too!
Comment #15
manila555 CreditAttribution: manila555 commentedThanks roball!
#7 worked like a charm.
Comment #16
serialbob CreditAttribution: serialbob commented#7 worked partially, the first and the end div stayed alive :-(
Comment #17
gejo CreditAttribution: gejo commentedThanks, roball!
Your solution in #7 worked like a charm for me.
Comment #18
stephesk8s CreditAttribution: stephesk8s commentedI also needed to export multiple node reference titles from a feeds View to a .csv file. I'm migrating our content from our current D6 site to our new D7 site, so I need to be able to explode the list with Feeds Tamper on the other end, but found nothing to add a separator to the grouped multiple values.
My field was set up as a Content: Node Reference field, (in my case "Content: Related Documents (field_related_documents)") and the Group Multiple Values was checked. The formatter was Title (no link).
By default, the titles are exported with no separator - i.e "Title OneTitle TwoTitle Three".
I had already been using the Custom Formatter module to grab the database key value for other field imports, so I set up a custom formatter for my Node Reference field with the [title-raw] token and a separator (in my case, I've had good luck with >> exploding well in Feeds Tamper so for this formatter it was [title-raw]>>).
Then in my Views display I was able to choose my new custom formatter for the format of my node reference field and the separator was added. Voila :)
(My custom formatter was very basic, so I had to find and replace away the last extra set of >>'s in my final .csv file in my text editor. I'm sure there is a more elegant way set up the formatter, but for me, this worked for my one time export. Also my D6 site is using Views 2 in case that makes a difference here.)
Comment #19
styledata@yahoo.com CreditAttribution: styledata@yahoo.com commented#7 works GREAT!
Comment #20
wooody CreditAttribution: wooody commented#7 Thank you roball ...
Comment #21
Vali Hutchison CreditAttribution: Vali Hutchison commentedCan also do it via CSS, for example:
Comment #22
garbo CreditAttribution: garbo commentedthis blog post has a handy solution to this: http://www.zyxware.com/articles/2970/solved-drupal-cck-group-multiple-va...
Comment #23
vrajak@gmail.com CreditAttribution: vrajak@gmail.com as a volunteer commented*edit* Can't seem to delete this post, but I figured it out so need for it.
Comment #24
squarecandy CreditAttribution: squarecandy commented+1 for using Custom Formatters module for CSV export issues (#18).
Install https://www.drupal.org/project/custom_formatters
Add a new formatter admin/build/formatters/add
I used the Basic type of formatter with the field type text and entered in the HTML field:
[raw]|
(I used the pipe character here, but you can use whatever unique separator you want).
Then go in and edit the view, edit the field in question with multi values, select your custom text format under the format drop down.
I know this thread is old, but hopefully this will help someone.
Comment #25
zkrebs CreditAttribution: zkrebs commentedThanks #24 squarecandy,
Used this for an old D6 migration and it worked beautifully.
Comment #26
gumrol CreditAttribution: gumrol commented+1 for #18 and #24
I wanted no trailing delimiter, so opted for the Advanced formatter type and did the following:
Comment #27
frederickjh@gumrol Thanks for your code in #26!
It is working for a number of fields.
However, it is not working for email address fields. I think it is the @ in the email addresses.
Anyone know how to handle email address correctly for a custom formater?
Thanks!
Frederick
Comment #28
frederickjh@gumrol Oh, forgot to say with your custom formater code I get the delimiters but no email addresses.
Comment #29
frederickjhDelimiting custom formatters for Links and Emails require a change to the code above in comment #26:
Replace this line:
$a_items[] = trim($element[$key]['#item']['value']);
For links:
$a_items[] = trim($element[$key]['#item']['url']);
For email addresses:
$a_items[] = trim($element[$key]['#item']['email']);