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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

How to convert DropdownField to SelectionGroup


Go to End


2 Posts   836 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.