From b9fa4e16735485fc444f2dd164dcebedc8571d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99i=20Dorazil?= Date: Fri, 11 Jan 2019 23:49:23 +0100 Subject: [PATCH] Fix duplicate container added with default values Fix InvalidArgumentException - container already created by default data --- src/Container.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Container.php b/src/Container.php index 6b2dfda..333011a 100644 --- a/src/Container.php +++ b/src/Container.php @@ -260,8 +260,12 @@ protected function createDefault() } if (!$this->getForm()->isSubmitted()) { - foreach (range(0, $this->createDefault - 1) as $key) { - $this->createOne($key); + $i = 0; + while (iterator_count($this->getContainers()) < $this->createDefault) { + if (!isset($this->created[$i])) { + $this->createOne($i); + } + $i++; } } elseif ($this->forceDefault) {