Skip to content

Commit

Permalink
Merge pull request filamentphp#14896 from dododedodonl/fix/item-valid…
Browse files Browse the repository at this point in the history
…ation

Fix item validation
  • Loading branch information
danharrin authored Nov 29, 2024
2 parents c69d5af + 4232b6f commit caff9ed
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/forms/src/Components/Concerns/CanLimitItemsLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ public function maxItems(int | Closure | null $count): static
{
$this->maxItems = $count;

$this->rule('array');
$this->rule('array', static function (Component $component): bool {
/** @var static $component */
$count = $component->getMaxItems();

return $count !== null;
});
$this->rule(static function (Component $component): string {
/** @var static $component */
$count = $component->getMaxItems();

return "max:{$count}";
}, static function (Component $component): bool {
/** @var static $component */
$count = $component->getMaxItems();

return $count !== null;
});

return $this;
Expand All @@ -30,12 +40,22 @@ public function minItems(int | Closure | null $count): static
{
$this->minItems = $count;

$this->rule('array');
$this->rule('array', static function (Component $component): bool {
/** @var static $component */
$count = $component->getMinItems();

return $count !== null;
});
$this->rule(static function (Component $component): string {
/** @var static $component */
$count = $component->getMinItems();

return "min:{$count}";
}, static function (Component $component): bool {
/** @var static $component */
$count = $component->getMinItems();

return $count !== null;
});

return $this;
Expand Down

0 comments on commit caff9ed

Please sign in to comment.