diff --git a/code/FileAttachmentField.php b/code/FileAttachmentField.php index ab845cd..7bc2b2f 100644 --- a/code/FileAttachmentField.php +++ b/code/FileAttachmentField.php @@ -577,7 +577,23 @@ public function setAcceptedFiles($files = array ()) { if(is_array($files)) { $files = implode(',', $files); } - $this->settings['acceptedFiles'] = str_replace(' ', '', $files); + $files = str_replace(' ', '', $files); + $this->settings['acceptedFiles'] = $files; + + // Update validator + $validator = $this->getValidator(); + if ($validator) { + $fileExts = explode(',', $files); + + $validatorExts = array(); + foreach ($fileExts as $fileExt) { + if ($fileExt && isset($fileExt[0]) && $fileExt[0] === '.') { + $fileExt = substr($fileExt, 1); + } + $validatorExts[] = $fileExt; + } + $validator->setAllowedExtensions($validatorExts); + } return $this; }