17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2562 Views |
-
Enumerates and ListboxField

9 January 2008 at 11:04pm
Hi all:
I´m new to SilverStripe. Thanks for this pretty work!
Based on the tutorial 2 "Extending a basic site" i´m trying to make a News page type.
The difference between my news page type and the page type in this sample is that i need to have different news types.
So, in the database definition i put this:
static $db = array
(
'Date' => 'Date',
'Author' => 'Text',
'Type' => "Enum('Type1,Type2,Type3,General','General')"
);
It works good. The database is created without problems.The problem comes with the getCMSFields function.
I need to select one of the news types when i write a new, so my getCMSFields looks like this:function getCMSFields()
{
$fields = parent::getCMSFields();$fields->addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Author'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new ListboxField('Type'), 'Content');return $fields;
}
I use ListboxField and, when i write a new news page i expect to have a combo with the options: Type1, Type2, Type3 and General. But i only have an empty combo.What i´m doing bad?
Thanks in advance and excuse me for my poor english.
-
Re: Enumerates and ListboxField

10 January 2008 at 12:48am
Perhaps the $fields->addFieldToTab('Root.Content.Main', new ListboxField('Type'), 'Content'); needs more arguments, see: http://api.silverstripe.com/default/ListboxField.html
Does this help?
-
Re: Enumerates and ListboxField

10 January 2008 at 3:16am
Hi SilverRay:
Thanks for your answer.
But if i don´t understand bad there is just one argument necessary in a list box (the name):
ListboxField __construct (name $name, [title $title = ""], [source $source = array()], [value $value = array()], [form $size = null], [ $multiple = null], [ $form = null])
I´m not right?
-
Re: Enumerates and ListboxField

12 January 2008 at 1:48pm
this field doesn't auto-populate (we try to minimize the "magic" a bit to keep things easily debuggable *g*).
i've updated the documentation of DropdownField (parent-class of ListboxField) to show an example which automatically gets the values of an Enum:
http://doc.silverstripe.com/doku.php?id=dropdownfield -
Re: Enumerates and ListboxField

14 January 2008 at 10:53pm
Hi Ingo:
Thank you, it works perfectly.
Another option was to put like this:
$fields->addFieldToTab("Root.Content.Main", new DropdownField( 'Type' , ''Type' ', array(
'Type1' => 'Type1',
'Type2' => 'Type2',
'Type3' => 'Type3',
'General' => 'General'
)));The only problem is, as you say, that it doesn´t auto populate. If you change the enum you have remember to change the DropdownField, but this is not a problem for me.
bye...
-
Re: Enumerates and ListboxField

15 January 2008 at 8:39am
"auto-populate" in the sense of loading a value: just add a fourth parameter from an existing object (usually $this->Type when you're in getCMSFields()), which will preselect the right entry
-
Re: Enumerates and ListboxField

16 April 2008 at 12:32am
Hi Ingo,
Is there are way to select the stored enum value from the list without adding it to the list of options?
My item status select box looks a little strange with the following.
Active
Archived
Activecheers.
-
Re: Enumerates and ListboxField

16 April 2008 at 12:52am
nevermind, I worked it out.
static $db = array(
'ItemStatus' => "Enum('Active, Archived','Active')"
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new DropdownField( 'ItemStatus' , 'ItemStatus', array( 'Active' => 'Active', 'Archived' => 'Archived'),$this->ItemStatus));
return $fields;
}
| 2562 Views | ||
|
Page:
1
|
Go to Top |


