Skip to content

Commit

Permalink
Merge pull request #5 from Ciki/patch-1
Browse files Browse the repository at this point in the history
add support for Form::MIN and Form::MAX rules
  • Loading branch information
hrach authored Sep 3, 2021
2 parents ca33c38 + eccc3d3 commit 33b93a0
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 33b93a0

Please sign in to comment.