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 /

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

How to convert DropdownField to SelectionGroup


Go to End
Reply


2 Posts   538 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, 5517 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.