5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1158 Views |
-
Select value in dropdownfield by default based on parent

21 May 2009 at 2:53am Last edited: 21 May 2009 2:54am
What I want to do is to select a certain value in a dropdownfield by default based on the value of the parent (that has the exact same dropdownfield). Why can't I get this field to display the parent value by default in the CMS?
public static $db = array(
'ResponsibleOffice' => 'Int'
};(...)
/**
* Overload so that the default value is same as parent.
* Based on same function in BlogEntry.php
*/
public function populateDefaults() {
parent::populateDefaults();
$this->setField('ResponsibleOffice', $parent->ResponsibleOffice);
}(...)
public function getCMSFields() {
$fields = parent::getCMSFields();$options = array('Value1', 'Value2', 'Value3', 'Value4');
$fields->addFieldToTab("Root.Content.Main", new DropdownField("ResponsibleOffice", "Responsible office", $options), 'Content');return $fields;
} -
Re: Select value in dropdownfield by default based on parent

21 May 2009 at 10:14pm
Found populatedefaults recipe here. Following this example I now have:
public function populateDefaults() {
parent::populateDefaults();
$parent_object = $this->getParent();
$this->ResponsibleOffice = $parent_object->getField('ResponsibleOffice');
}Now, when adding this page as a child to another page, I get a 'Javascript parse error' in the CMS. What am I doing wrong?
| 1158 Views | ||
|
Page:
1
|
Go to Top |

