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   450 Views

Avatar
mayko80

Community Member, 1 Post

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, 5513 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.