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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

cant use dropdown on update


Go to End


5 Posts   993 Views

Avatar
dacar

Community Member, 173 Posts

6 October 2009 at 10:39am

hi,

i have inserted a dropdown to my fieldSet. But it is only available on insert but not on update. Can anybody explain this behaviour?

return new FieldSet(
new DropdownField(
$name = 'StammdatenID',
$title = 'Firma wählen',
$source = $map,
$value = $this->StammdatenID
),

Avatar
dalesaurus

Community Member, 283 Posts

6 October 2009 at 3:31pm

You might want to try specific questions like this in the Forms forum.

A bit more info would be helpful also. Are you creating a form or extending the CMS? Where are you trying to insert and update?

Avatar
dacar

Community Member, 173 Posts

6 October 2009 at 10:04pm

Hi dalesaurus,

you are right. This is the wrong forum for this question.

for the use in the CMS i have written these lines into stammdaten.php:

class Stammdaten extends DataObject {
static $singular_name = 'Stammdaten';
static $plural_name = 'Stammdaten';

static $db = array(
'Firmenname' => 'Varchar',
'Strasse' => 'Varchar',
'PLZ' => 'Int',
'Ort' => 'Varchar',
'Vorwahl' => 'Int',
'Telefon' => 'Int',
'Fax' => 'Int',
'Mail' => 'Varchar',
'Web' => 'Varchar'
);

function getCMSFields() {

$fields = new FieldSet(
new TextField('Firmenname', 'Firmenname'),
new DropdownField(
'ID',
'Bitte einen Bereich waehlen.',
Dataobject::get("SiteTree", "SiteTree.ParentID = '20'", "SiteTree.ID", "", "")->toDropdownMap("ID", "Title")
),
new TextField('Strasse', 'Strasse'),
new NumericField('PLZ', 'PLZ'),
new TextField('Ort', 'Ort'),
new NumericField('Vorwahl', 'Vorwahl'),
new NumericField('Telefon', 'Telefon'),
new NumericField('Fax', 'Fax'),
new EmailField('Mail', 'Mail'),
new TextField('Web', 'Web')
);

return $fields;
}

static $has_one = array(
'LogoGesamtuebersicht' => 'Stammdaten_Thumbnail',
'LogoDetailuebersicht' => 'Stammdaten_Thumbnail',
'LogoLaufband' => 'Stammdaten_Thumbnail'
);

static $searchable_fields = array (
'Firmenname',
'PLZ',
'Ort',
'Ansprechpartner.Nachname'
);

static $summary_fields = array(
'Firmenname',
'PLZ',
'Ort'
);

static $field_labels = array (
//'Ansprechpartner.Nachname'
);

static $has_many = array(
'Ansprechpartner' => 'Ansprechpartner',
'Referenzen' => 'Referenz'
);

public function SplitList($val=5) {
return ($this->iteratorPos + 1) % $val == 0;
}
}

Avatar
dalesaurus

Community Member, 283 Posts

7 October 2009 at 7:45am

Ah hah!

 new DropdownField(
            'ID', 

You're attempting to overwrite the ID field, which is central to every SS object in the ORM. When you're creating a row hasn't yet been created in the DB with an index ID, thus you can specify. On subsequent accesses your form does not populate existing data, nor will it be able to change the ID.

I think you need to revise your strategy and work with the parent::getCMSFields() return instead, and create a new field for whatever you are storing in the dropdown.

Avatar
dacar

Community Member, 173 Posts

7 October 2009 at 11:45am

Hi Dalesaurus,

you are absolutely right. I have changed it and it works great.