From eccc3d38fa237ee2193ec2b910453f317bb20ea7 Mon Sep 17 00:00:00 2001 From: Ciki Date: Thu, 2 Sep 2021 16:22:20 +0200 Subject: [PATCH] add support for Form::MIN and Form::MAX rules extended support of Form rules, in addition to Form::RANGE --- src/Controls/DateTimeControlPrototype.php | 29 +++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Controls/DateTimeControlPrototype.php b/src/Controls/DateTimeControlPrototype.php index ba31871..499b380 100644 --- a/src/Controls/DateTimeControlPrototype.php +++ b/src/Controls/DateTimeControlPrototype.php @@ -117,28 +117,31 @@ protected function extractRangeRule(Rules $rules) $controlMin = $controlMax = null; /** @var Nette\Forms\Rule $rule */ foreach ($rules as $rule) { + $ruleMin = $ruleMax = null; + /** @var Rules|null $branch */ $branch = $rule->branch; if ($branch === null) { - if ($rule->validator === Form::RANGE && !$rule->isNegative) { - $ruleMinMax = $rule->arg; + if (!$rule->isNegative) { + if ($rule->validator === Form::MIN) { + $ruleMin = $rule->arg; + } elseif ($rule->validator === Form::MAX) { + $ruleMax = $rule->arg; + } elseif ($rule->validator === Form::RANGE) { + list($ruleMin, $ruleMax) = $rule->arg; + } } - } else { if ($rule->validator === Form::FILLED && !$rule->isNegative && $rule->control === $this) { - $ruleMinMax = $this->extractRangeRule($branch); + list($ruleMin, $ruleMax) = $this->extractRangeRule($branch); } } - if (isset($ruleMinMax)) { - list($ruleMin, $ruleMax) = $ruleMinMax; - if ($ruleMin !== null && ($controlMin === null || $ruleMin > $controlMin)) { - $controlMin = $ruleMin; - } - if ($ruleMax !== null && ($controlMax === null || $ruleMax < $controlMax)) { - $controlMax = $ruleMax; - } - $ruleMinMax = null; + if ($ruleMin !== null && ($controlMin === null || $ruleMin > $controlMin)) { + $controlMin = $ruleMin; + } + if ($ruleMax !== null && ($controlMax === null || $ruleMax < $controlMax)) { + $controlMax = $ruleMax; } } return [$controlMin, $controlMax];