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.

Customising the CMS /

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

DropDown in ModelAdmin not diplaying value. (has_many relationship)


Go to End


914 Views

Avatar
TwinkleToes

Community Member, 1 Post

1 October 2015 at 3:58am

Edited: 01/10/2015 8:37pm

Greetings.

I have a dropdown menu on ModelAdmin that, by default, displays the primary-key/ID. I want said dropdown rather to display the Value. Please advise.

My code is as follows:

<?php

class Player extends DataObject {

    private static $db = array(
        'PlayerName'=>'Varchar(50)',
		'DateJoined'=>'Date',
		'Tries'=>'Int',
		'DropGoals'=>'Int',
		'Penalties'=>'Int',
		'Conversions'=>'Int',
    );
	
	  private static $has_one = array(
    	"TeamJoin"=>"Team"
  );

	   private static $field_labels = array(
      'PlayerName'=>'Name of Player',
	  'DateJoined'=>'Date of Joining',
	  'Tries'=>	'Total Tries Scored',
	  'DropGoals'=>'Total Drop Kicks Scored',
	  'Penalties'=>'Number of Penalties Converted',
	  'Conversions'=>'Number of Tries Converted',
	  'TeamJoin'=>'Team this player belongs to',
   );
	
	   private static $summary_fields = array(
      'PlayerName',
	  'DateJoined',
	  'Team',
   );
   
    public function getCMSfield() {
	   $fields->removeByName('TeamJoin');
	   $fields = Fieldlist::create(
	   		TextField::create('PlayerName'),
			DateField::create('DateJoined')
			->setConfig('showcalendar', true),
			NumericField::create('Tries'),
			NumericField::create('DropGoals'),
			NumericField::create('Penalties'),
			NumericField::create('Conversions'),
                        DropdownField::create('TeamJoin')
			);	
}
}

Thanks!
//TwinkleToes