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.

Archive

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

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

TableField Dropdown


Reply

4 Posts   1742 Views

Avatar
UncleCheese

27 October 2007 at 9:12am 4085 Posts

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"
);

Avatar
jam13

27 October 2007 at 11:30am 121 Posts

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

Avatar
Sigurd

27 October 2007 at 1:33pm Forum Moderator, 628 Posts

Its the same as http://doc.silverstripe.com/doku.php?id=optionsetfield

Avatar
jam13

29 October 2007 at 5:23am 121 Posts

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