Jump to:

10845 Posts in 2516 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » MultiSelectField: combine two strings?

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 744 Views
  • Felicitas
    Avatar
    Community Member
    16 Posts

    MultiSelectField: combine two strings? Link to this post

    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')));

  • jam13
    Avatar
    121 Posts

    Re: MultiSelectField: combine two strings? Link to this post

    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

  • Felicitas
    Avatar
    Community Member
    16 Posts

    Re: MultiSelectField: combine two strings? Link to this post

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

    744 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.