From 02b879cfdf2b44d0d5649209ce45af61aab6a37f Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sun, 3 Oct 2021 03:18:23 +0200 Subject: [PATCH] Fix rules set in CustomInputModifier not being propagated to JS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to this extremely confusing change, client side validation for custom rules on category field got broken: https://github.com/nette/forms/commit/1592cf64cfa4dcd80e621556b375f45dec9ae969 Let’s apply the hack from the commit. Opened an issue: https://github.com/nette/forms/issues/278 --- app/forms/TeamFormFactory.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/forms/TeamFormFactory.php b/app/forms/TeamFormFactory.php index 8385198..ba2c903 100644 --- a/app/forms/TeamFormFactory.php +++ b/app/forms/TeamFormFactory.php @@ -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 */ @@ -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 */