I populate a DropDownField automatically from an array as :
function getCMSFields() {
$fields = new FieldSet( new DropdownField(
'CountryName',
'Choose a country',
Dataobject::get("country")->toDropdownMap("CountryName", "CountryName")
), ..etc ..
}
This works very well when 'country' already contains data. However I get an error when at init. there
is **no country** yet in the database.
I understand this is because Dataobject::get() is NULL and therefore the call to toDropdownMap fails.
So I tried to use a function which tests if 'country' is empty or not :
function CreateCountryList() {
$myDataSet = DataObject::get("country");
if (!$myDataSet) return false;
else
return $myDataSet->toDropdownMap("CountryName", "CountryName");
}
$fields = new FieldSet( new DropdownField(
'CountryName',
'Choose a country',
$this->CreateCountryList()
),
etc...
But with that, I can not properly create a country for the customer with the DOM. (i.e the entry is written in the DB but the DOM
does not display it in the table and returns the error messages :
ERROR [Warning]: Missing argument 3 for ComplexTableField_Item::__construct(), called in /home/www/xxx.com/dataobject_manager/code/DataObjectManager.php on line 584 and defined
IN POST /admin/getitem?ID=11&ajax=1
Line 980 in /home/www/xxx.com/sapphire/forms/ComplexTableField.php
I guess my CreateCountryList() is wrong so my question is ...how to create an empty DropDownField ?
I hope this is not too confusing ...
Thanks in advance for any tip,
Lise
PS. I am running SS 2.3.7 with the latest DOM ( March 23 )