Skip to content

Commit c247a41

Browse files
authored
Merge pull request #21 from dipcode-software/bugfix/file-field-validator
Allow file field not required
2 parents 4998162 + ada5b1a commit c247a41

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Fields/FileField.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ public function __construct(array $args = array())
3131

3232
public function validate($value)
3333
{
34-
if (0 == $value->size && $this->required) {
34+
if (is_null($value) && !$this->required) {
35+
return;
36+
}
37+
if (is_null($value) && $this->required || 0 == $value->size && $this->required) {
3538
throw new ValidationError($this->error_messages['required'], 'required');
3639
}
3740

@@ -51,6 +54,9 @@ public function validate($value)
5154

5255
public function toNative($value)
5356
{
57+
if (is_null($value)) {
58+
return null;
59+
}
5460
if (!is_array($value)) {
5561
throw new ValidationError(msg("INVALID_FILE"), 'invalid');
5662
}

0 commit comments

Comments
 (0)