Merge pull request #280 from tractorcow/pulls/fix-file-validation

BUG Fix file field ignoring allowed extensions
This commit is contained in:
Daniel Hensby 2015-07-16 12:14:37 +01:00
commit 7e29aab0ba
3 changed files with 136 additions and 117 deletions

View File

@ -32,6 +32,11 @@ class EditableFileField extends EditableFormField {
public function getFormField() {
$field = FileField::create($this->Name, $this->Title);
// filter out '' since this would be a regex problem on JS end
$field->getValidator()->setAllowedExtensions(
array_filter(Config::inst()->get('File', 'allowed_extensions'))
);
if($this->getSetting('Folder')) {
$folder = Folder::get()->byId($this->getSetting('Folder'));

View File

@ -327,6 +327,14 @@ class EditableFormFieldTest extends FunctionalTest {
$this->assertNotNull($validationField);
}
public function testFileField() {
$fileField = $this->objFromFixture('EditableFileField', 'file-field');
$formField = $fileField->getFormField();
$this->assertContains('jpg', $formField->getValidator()->getAllowedExtensions());
$this->assertNotContains('notallowedextension', $formField->getValidator()->getAllowedExtensions());
}
}
/**

View File

@ -103,6 +103,12 @@ EditableRadioField:
Options: =>EditableOption.option-5, =>EditableOption.option-6
EditableFileField:
file-field:
Name: file-uploader
Title: Set file
ExtendedEditableFormField:
extended-field:
Name: extended-field