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.

All other Modules /

Discuss all other Modules here.

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

MultiSelectField: combine two strings?


Reply


3 Posts   899 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.