Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

将index唯一化,防止出现两个或多个相同字段时全局index变量失效。 #5688

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/Form/Field/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,14 @@ protected function setupScriptForDefaultView($templateScript)
* {count} is increment number of current sub form count.
*/
$script = <<<EOT
var index = 0;
var index_$this->column = 0;
$('#has-many-{$this->column}').off('click', '.add').on('click', '.add', function () {

var tpl = $('template.{$this->column}-tpl');

index++;
index_$this->column++;

var template = tpl.html().replace(/{$defaultKey}/g, index);
var template = tpl.html().replace(/{$defaultKey}/g, index_$this->column);
$('.has-many-{$this->column}-forms').append(template);
{$templateScript}
return false;
Expand Down Expand Up @@ -543,11 +543,11 @@ protected function setupScriptForTabView($templateScript)
}
});

var index = 0;
var index_$this->column = 0;
$('#has-many-{$this->column} > .header').off('click', '.add').on('click', '.add', function(){
index++;
var navTabHtml = $('#has-many-{$this->column} > template.nav-tab-tpl').html().replace(/{$defaultKey}/g, index);
var paneHtml = $('#has-many-{$this->column} > template.pane-tpl').html().replace(/{$defaultKey}/g, index);
index_$this->column++;
var navTabHtml = $('#has-many-{$this->column} > template.nav-tab-tpl').html().replace(/{$defaultKey}/g, index_$this->column);
var paneHtml = $('#has-many-{$this->column} > template.pane-tpl').html().replace(/{$defaultKey}/g, index_$this->column);
$('#has-many-{$this->column} > .nav').append(navTabHtml);
$('#has-many-{$this->column} > .tab-content').append(paneHtml);
$('#has-many-{$this->column} > .nav > li:last-child a').tab('show');
Expand Down Expand Up @@ -588,14 +588,14 @@ protected function setupScriptForTableView($templateScript)
* {count} is increment number of current sub form count.
*/
$script = <<<EOT
var index = 0;
var index_$this->column = $('#has-many-{$this->column} table tbody').children().length;
$('#has-many-{$this->column}').on('click', '.add', function () {

var tpl = $('template.{$this->column}-tpl');

index++;
index_$this->column=($('#has-many-{$this->column} table tbody').children().length)+1;

var template = tpl.html().replace(/{$defaultKey}/g, index);
var template = tpl.html().replace(/{$defaultKey}/g, index_$this->column);
$('.has-many-{$this->column}-forms').append(template);
{$templateScript}
return false;
Expand Down