Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

MultiSelectField: combine two strings?


Go to End


3 Posts   1777 Views

Avatar
Felicitas

Community Member, 16 Posts

27 April 2011 at 8:52pm

Hi, I am using the MultiSelectField module (see code). Is it possible two show a combination of for example 'Title' and a second text field (in my case 'Edition'. Something like 'Title . "and" . Edition'?

$participantlist = DataObject::get('Participant','','Title ASC'); 
$fields->addFieldToTab('Root.Content.Main', new MultiSelectField('Participants', 'Active participants', $participantlist->map('ID','Title')));

Avatar
jam13

121 Posts

28 April 2011 at 1:04am

Edited: 28/04/2011 1:05am

Easiest way to do it is to create a method in your Participant class:

class Participant extends DataObject {
  //...
  function getLongTitle() {
    return $this->Title . ' and ' . $this->Edition;
  }

and then you can call:

$participantlist->map('ID','LongTitle');

Jamie

Avatar
Felicitas

Community Member, 16 Posts

28 April 2011 at 5:15am

Thank you. Very useful, because I have a long list of participants and some of them have almost the same 'Title' field.