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.

Form Questions

How to convert DropdownField to SelectionGroup


Reply

2 Posts   390 Views

Avatar
mayko80

18 July 2013 at 8:57pm Community Member, 1 Post

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

19 July 2013 at 8:49pm Forum Moderator, 5511 Posts

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