Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » TableField Dropdown

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1720 Views
  • UncleCheese
    Avatar
    4085 Posts

    TableField Dropdown Link to this post

    I've always set up my TableFields with TextFields. Is it possible to put a DropdownField in? When i do, it appears, but it's not populated. How can I populate it?

    new TableField(
    'Practice_Areas',
    'PracticeAreas',
    array(
        'Practice_Area' => 'Practice Area',
        'Link' => 'Link'
    ),
    array(
        'Practice_Area' => 'TextField',
        'Link' => 'DropdownField' /** Where do the options go?? **/
    ),
    null,
          "PracticeAreas.AttorneyPageID = $this->ID"
    );

  • jam13
    Avatar
    121 Posts

    Re: TableField Dropdown Link to this post

    I do it like this:

    $myFieldNames = array(
    'Options' => 'Options'
    );
    $myFieldTypes = array(
    'Options' => new DropdownField('Options','Options',array(
    '' => '',
    'Option 1' => 1,
    'Option 2' => 2,
    'Option 3' => 3
    ))
    );
    $myTableField = new TableField('MyTable', 'MyTable', $myFieldNames, $myFieldTypes, null, "ForeignID = {$this->ID}");

    Whether that's the "right" way I'm not sure (it's the only way that I've got to work).

  • Sigurd
    Avatar
    Forum Moderator
    628 Posts
  • jam13
    Avatar
    121 Posts

    Re: TableField Dropdown Link to this post

    I think the confusion is (at least it confused me) that the TableField docs show how to pass an array of field types to create the table, which doesn't work with a more complex field like a dropdown. What it doesn't show is that you can pass it a FieldSet (as in the ComplexTableField docs).

    1720 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.