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.

Form Questions /

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

How to convert DropdownField to SelectionGroup


Go to End


2 Posts   1318 Views

Avatar
mayko80

Community Member, 2 Posts

18 July 2013 at 8:57pm

Hi guys,

Is there an easier way to convert a DropdownField to a SelectionGroup from an enum field?

Maybe something like this?

$fields = $this->scaffoldFormFields(
    array(
        'fieldClasses' => array(
             'SomeField' => 'SelectionGroup',
        )
    )
);

or do have to do this?

$name = $fields->dataFieldByName('SomeField')->getAttributes()["name"];
$values = $fields->dataFieldByName('SomeField')->getSource();
$items = array();
foreach($values as $value) {
    $items[] = SelectionGroup_Item::create($value, null, $value);
}
$convertedField = SelectionGroup::create($name, $items);
$fields->push($convertedField);

Avatar
Willr

Forum Moderator, 5523 Posts

19 July 2013 at 8:49pm

Does the former method work? It would seem like that would be an option. SelectionGroup field may just need a few tricks.