diff --git a/src/Form/Field/HasMany.php b/src/Form/Field/HasMany.php index e8f4b09ed8..b6aeccbdb6 100644 --- a/src/Form/Field/HasMany.php +++ b/src/Form/Field/HasMany.php @@ -488,14 +488,14 @@ protected function setupScriptForDefaultView($templateScript) * {count} is increment number of current sub form count. */ $script = <<column}').off('click', '.add').on('click', '.add', function () { var tpl = $('template.{$this->column}-tpl'); - index++; + var index = $('.has-many-{$this->column}-form').length; - var template = tpl.html().replace(/{$defaultKey}/g, index); + var template = tpl.html().replace(/{$defaultKey}/g, index + 1); $('.has-many-{$this->column}-forms').append(template); {$templateScript} return false; @@ -588,14 +588,13 @@ protected function setupScriptForTableView($templateScript) * {count} is increment number of current sub form count. */ $script = <<column}').on('click', '.add', function () { var tpl = $('template.{$this->column}-tpl'); - index++; + var index = $('.has-many-{$this->column}-form').length; - var template = tpl.html().replace(/{$defaultKey}/g, index); + var template = tpl.html().replace(/{$defaultKey}/g, index + 1); $('.has-many-{$this->column}-forms').append(template); {$templateScript} return false;