diff --git a/domain-server/resources/web/settings/js/settings.js b/domain-server/resources/web/settings/js/settings.js
index 2947983ef9..3196213e4a 100644
--- a/domain-server/resources/web/settings/js/settings.js
+++ b/domain-server/resources/web/settings/js/settings.js
@@ -39,7 +39,8 @@ var Settings = {
ACCESS_TOKEN_SELECTOR: '[name="metaverse.access_token"]',
PLACES_TABLE_ID: 'places-table',
FORM_ID: 'settings-form',
- INVALID_ROW_CLASS: 'invalid-input'
+ INVALID_ROW_CLASS: 'invalid-input',
+ DATA_ROW_INDEX: 'data-row-index'
};
var viewHelpers = {
@@ -223,10 +224,10 @@ $(document).ready(function(){
// set focus to the first input in the new row
$target.closest('table').find('tr.inputs input:first').focus();
}
-
+
var tableRows = sibling.parent();
var tableBody = tableRows.parent();
-
+
// if theres no more siblings, we should jump to a new row
if (sibling.next().length == 0 && tableRows.nextAll().length == 1) {
tableBody.find("." + Settings.ADD_ROW_BUTTON_CLASS).click();
@@ -1005,7 +1006,7 @@ function saveSettings() {
var password = formJSON["security"]["http_password"];
var verify_password = formJSON["security"]["verify_http_password"];
- // if they've only emptied out the default password field, we should go ahead and acknowledge
+ // if they've only emptied out the default password field, we should go ahead and acknowledge
// the verify password field
if (password != undefined && verify_password == undefined) {
verify_password = "";
@@ -1158,8 +1159,9 @@ function makeTable(setting, keypath, setting_value) {
}
html += "
"
@@ -1292,12 +1294,12 @@ function makeTableHiddenInputs(setting, initialValues, categoryValue) {
} else if (col.type === "select") {
html += "
"
html += "";
html += "
";
} else {
@@ -1398,6 +1400,15 @@ function addTableRow(row) {
var setting_name = table.attr("name");
row.addClass(Settings.DATA_ROW_CLASS + " " + Settings.NEW_ROW_CLASS);
+ // if this is an array, add the row index (which is the index of the last row + 1)
+ // as a data attribute to the row
+ var row_index = 0;
+ if (isArray) {
+ var previous_row_index = parseInt(row.siblings('.' + Settings.DATA_ROW_CLASS + ':last').attr(Settings.DATA_ROW_INDEX), 10);
+ row_index = previous_row_index + 1;
+ row.attr(Settings.DATA_ROW_INDEX, row_index);
+ }
+
var focusChanged = false;
_.each(row.children(), function(element) {
@@ -1430,7 +1441,6 @@ function addTableRow(row) {
var isDropdown = input.hasClass("table-dropdown");
if (isArray) {
- var row_index = row.siblings('.' + Settings.DATA_ROW_CLASS).length
var key = $(element).attr('name');
// are there multiple columns or just one?
@@ -1438,16 +1448,13 @@ function addTableRow(row) {
var num_columns = row.children('.' + Settings.DATA_COL_CLASS).length
var newName = setting_name + "[" + row_index + "]" + (num_columns > 1 ? "." + key : "");
- if (isCheckbox) {
- input.attr("name", newName)
- } else {
- if (isDropdown) {
- // default values for hidden inputs inside child selects gets cleared so we need to remind it
- var selectElement = $(element).children("select");
- selectElement.attr("data-hidden-input", newName);
- $(element).children("input").val(selectElement.val());
- }
- input.attr("name", newName);
+ input.attr("name", newName);
+
+ if (isDropdown) {
+ // default values for hidden inputs inside child selects gets cleared so we need to remind it
+ var selectElement = $(element).children("select");
+ selectElement.attr("data-hidden-input", newName);
+ $(element).children("input").val(selectElement.val());
}
} else {
// because the name of the setting in question requires the key
@@ -1462,10 +1469,10 @@ function addTableRow(row) {
input.focus();
focusChanged = true;
}
-
+
// if we are adding a dropdown, we should go ahead and make its select
// element is visible
- if (isDropdown) {
+ if (isDropdown) {
$(element).children("select").attr("style", "");
}