Jump to:

23450 Posts in 18899 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » cant use dropdown on update

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

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

Page: 1
Go to End
Author Topic: 680 Views
  • dacar
    Avatar
    Community Member
    168 Posts

    cant use dropdown on update Link to this post

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

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: cant use dropdown on update Link to this post

    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?

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: cant use dropdown on update Link to this post

    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;
          }
    }

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: cant use dropdown on update Link to this post

    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.

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: cant use dropdown on update Link to this post

    Hi Dalesaurus,

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

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