Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » How to convert DropdownField to SelectionGroup

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

Page: 1
Go to End
Author Topic: 358 Views
  • mayko80
    Avatar
    Community Member
    1 Post

    How to convert DropdownField to SelectionGroup Link to this 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);

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: How to convert DropdownField to SelectionGroup Link to this post

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

    358 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.