mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #280 from tractorcow/pulls/fix-file-validation
BUG Fix file field ignoring allowed extensions
This commit is contained in:
commit
7e29aab0ba
@ -32,6 +32,11 @@ class EditableFileField extends EditableFormField {
|
|||||||
public function getFormField() {
|
public function getFormField() {
|
||||||
$field = FileField::create($this->Name, $this->Title);
|
$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')) {
|
if($this->getSetting('Folder')) {
|
||||||
$folder = Folder::get()->byId($this->getSetting('Folder'));
|
$folder = Folder::get()->byId($this->getSetting('Folder'));
|
||||||
|
|
||||||
|
@ -327,6 +327,14 @@ class EditableFormFieldTest extends FunctionalTest {
|
|||||||
$this->assertNotNull($validationField);
|
$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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,6 +103,12 @@ EditableRadioField:
|
|||||||
Options: =>EditableOption.option-5, =>EditableOption.option-6
|
Options: =>EditableOption.option-5, =>EditableOption.option-6
|
||||||
|
|
||||||
|
|
||||||
|
EditableFileField:
|
||||||
|
file-field:
|
||||||
|
Name: file-uploader
|
||||||
|
Title: Set file
|
||||||
|
|
||||||
|
|
||||||
ExtendedEditableFormField:
|
ExtendedEditableFormField:
|
||||||
extended-field:
|
extended-field:
|
||||||
Name: extended-field
|
Name: extended-field
|
||||||
|
Loading…
Reference in New Issue
Block a user