From 7eb4e8ef838f855fc2595399376bfac4884c82ef Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 12 Apr 2010 03:17:09 +0000 Subject: [PATCH] BUGFIX: Fixed readonly form of TreeDropdownField when field is made readonly before value is set (from r94608) (from r96765) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102394 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/TreeDropdownField.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/forms/TreeDropdownField.php b/forms/TreeDropdownField.php index ba6f91df6..38d8008f5 100755 --- a/forms/TreeDropdownField.php +++ b/forms/TreeDropdownField.php @@ -206,5 +206,34 @@ class TreeDropdownField extends FormField { return DataObject::get_one($this->sourceObject, "\"{$this->keyField}\" = '" . Convert::raw2sql($key) . "'"); } } - + + /** + * Changes this field to the readonly field. + */ + function performReadonlyTransformation() { + return new TreeDropdownField_Readonly($this->name, $this->title, $this->sourceObject, $this->keyField, $this->labelField); + } } + +class TreeDropdownField_Readonly extends TreeDropdownField { + protected $readonly = true; + + function Field() { + $fieldName = $this->labelField; + if($this->value) { + $keyObj = $this->getByKey($this->value); + $obj = $keyObj ? $keyObj->$fieldName : ''; + } else { + $obj = null; + } + + $source = array( + $this->value => $obj + ); + + $field = new LookupField($this->name, $this->title, $source); + $field->setValue($this->value); + $field->setForm($this->form); + return $field->Field(); + } +} \ No newline at end of file