diff --git a/forms/UploadField.php b/forms/UploadField.php index f7c6e1056..cb0683328 100644 --- a/forms/UploadField.php +++ b/forms/UploadField.php @@ -305,6 +305,12 @@ class UploadField extends FileField { ); } + public function extraClass() { + if($this->isDisabled()) $this->addExtraClass('disabled'); + if($this->isReadonly()) $this->addExtraClass('readonly'); + return parent::extraClass(); + } + public function Field($properties = array()) { $record = $this->getRecord(); $name = $this->getName(); @@ -597,6 +603,21 @@ class UploadField extends FileField { if (isset($name) && isset($record)) return $record->getRelationClass($name); } + + public function isDisabled() { + return (parent::isDisabled() || !$this->isSaveable()); + } + + /** + * Determines if the field can be saved into a database record. + * + * @return boolean + */ + public function isSaveable() { + $record = $this->getRecord(); + // Don't allow upload or edit of a relation when the underlying record hasn't been persisted yet + return (!$record || !$this->managesRelation() || $record->exists()); + } } /** diff --git a/templates/UploadField.ss b/templates/UploadField.ss index 340d4c602..6a10370cd 100644 --- a/templates/UploadField.ss +++ b/templates/UploadField.ss @@ -26,6 +26,12 @@ <% end_if %> <% if isDisabled || isReadonly %> + <% if isSaveable %> + <% else %> +