Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function test($rule, $valueToTest, $fieldName = 'item'): bool
$rule = $matches[0];
}

if (in_array('optional', $rule) && empty($valueToTest)) {
if (in_array('optional', $rule) && ($valueToTest === null || $valueToTest === '' || $valueToTest === [])) {
return true;
}

Expand Down Expand Up @@ -175,7 +175,6 @@ protected function test($rule, $valueToTest, $fieldName = 'item'): bool
$param = $ruleParams;
}


if (strpos($currentRule, ':') !== false && strpos($currentRule, '|') === false) {
$ruleParts = explode(':', $currentRule);

Expand All @@ -191,7 +190,8 @@ protected function test($rule, $valueToTest, $fieldName = 'item'): bool
throw new \Exception("Rule $currentRule does not exist");
}

if (!$valueToTest) {
$isMissing = $valueToTest === null || $valueToTest === '' || ($valueToTest === []);
if ($isMissing) {
if ($expandedErrors) {
$this->addError($fieldName, str_replace(
['{field}', '{Field}', '{value}'],
Expand Down Expand Up @@ -247,6 +247,10 @@ protected function test($rule, $valueToTest, $fieldName = 'item'): bool
$param = [$param];
}

if (is_bool($valueToTest)) {
$valueToTest = $valueToTest ? '1' : '0';
}

if (is_float($valueToTest)) {
$valueToTest = json_encode($valueToTest, JSON_PRESERVE_ZERO_FRACTION);
}
Expand Down
Loading