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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

conditional (dynamic) values for fields in CMS - backend

Go to End

5 Posts   1579 Views


Community Member, 11 Posts

9 April 2013 at 9:01am

Edited: 09/04/2013 9:03am

Hi everyone,

I have a DataObject called Product and it has a few fields:

class Product extends DataObject {
//db fields
static $db = array(
'Name' => 'Varchar',
'MotorType' => 'Enum("-- select --,Induction,Single stage","-- select --")',
'Measurement'=> 'Enum("-- select --,KiloWatt,Watt","-- select --")'
// etc


My question is how can I (dynamically) set the value for Measurement field based on what I set for MotorType.

Assuming this is my getCMSFields() function:

//Fields for the DOM Popup
public function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Specifications', new DropdownField('MotorType', 'Motor Type',singleton('Product')->dbObject('MotorType')->enumValues()));
// ToDo: dynamic values for next field

If I choose "Induction" for MotorType, I want the Measurement field pick up the "KiloWatt" value automatically
If I choose "Single stage" for MotoType, the Measurement field should be set with "Watt" value (again dynamically).

Any thoughts?

Your help is much appreciated.


Community Member, 545 Posts

11 April 2013 at 1:22pm

Easist solution is to use jQuery to set the field. If you don't want the end user to able to change it you could just hide the field and do set in an onBeforeWrite.


Community Member, 11 Posts

11 April 2013 at 3:58pm

Thanks zenmonkey,
may I ask you to give me a quick example please?


Community Member, 545 Posts

11 April 2013 at 5:03pm

I forgot SS3 has moved to javascript dropdowns. Not sure if the use $("#FieldID").bind('change', function(){}); works. I woudl need to do a little more digging. Unless someone knows else knows off the op of their head how to bind events to SS3 dropdown changes

for the non user editable I would either remove the Measurment Field from the cms or only show it when ID == 0 so that it owuld show up for new items then add an onBeforeWrite

 public function onBeforeWrite() {
if ($this->MotorType == "Single stage") {
$this->Measurement = "Watt";
} else {
$this->Measurement = "KiloWatt";



Community Member, 11 Posts

12 April 2013 at 7:10am

much appreciated brother