Skip to content

Commit

Permalink
Fix rules set in CustomInputModifier not being propagated to JS
Browse files Browse the repository at this point in the history
Due to this extremely confusing change, client side validation for custom rules on category field got broken:

nette/forms@1592cf6

Let’s apply the hack from the commit.

Opened an issue: nette/forms#278
  • Loading branch information
jtojnar committed Oct 3, 2021
1 parent 9530d60 commit 02b879c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/forms/TeamFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ public function create(array $countries, string $locale, bool $editing = false,
if ($category->value !== null) {
$constraints = $this->categories->getCategoryData()[$category->value]['constraints'];
foreach ($constraints as $constraint) {
$category->addRule(...$constraint);
$rule = $category->addCondition(true); // not to block the export of rules to JS
$rule->addRule(...$constraint);
}
}

$category->addRule(function(CategoryEntry $entry) use ($defaultMaxMembers): bool {
$rule = $category->addCondition(true); // not to block the export of rules to JS
$rule->addRule(function(CategoryEntry $entry) use ($defaultMaxMembers): bool {
$category = $entry->getValue();
$maxMembers = $this->categories->getCategoryData()[$category]['maxMembers'] ?? $defaultMaxMembers;
/** @var \Kdyby\Replicator\Container */
Expand All @@ -72,7 +74,8 @@ public function create(array $countries, string $locale, bool $editing = false,
return iterator_count($replicator->getContainers()) <= $maxMembers;
}, 'messages.team.error.too_many_members_simple'); // TODO: add params like in add/remove buttons

$category->addRule(function(CategoryEntry $entry) use ($defaultMinMembers): bool {
$rule = $category->addCondition(true); // not to block the export of rules to JS
$rule->addRule(function(CategoryEntry $entry) use ($defaultMinMembers): bool {
$category = $entry->getValue();
$minMembers = $this->categories->getCategoryData()[$category]['minMembers'] ?? $defaultMinMembers;
/** @var \Kdyby\Replicator\Container */
Expand Down

0 comments on commit 02b879c

Please sign in to comment.