Skip to content

Commit

Permalink
add support for Form::MIN and Form::MAX rules
Browse files Browse the repository at this point in the history
extended support of Form rules, in addition to Form::RANGE
  • Loading branch information
Ciki authored Sep 2, 2021
1 parent ca33c38 commit eccc3d3
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/Controls/DateTimeControlPrototype.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit eccc3d3

Please sign in to comment.