Skip to content

Commit

Permalink
Improved logic for Tables min/max rows Fixed #2864
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler committed May 10, 2018
1 parent 95dafc1 commit e28f739
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Fixed warnings about missing SVG files that were logged by Control Panel requests.
- Fixed a bug where the `|date` filter would ignore date formatting characters that don’t have ICU counterparts. ([#2867](https://github.com/craftcms/cms/issues/2867))
- Fixed a bug where the global `currentUser` Twig variable could be set to `null` and global sets and could be missing some custom field values when a user was logged-in, if a plugin was loading Twig during or immediately after plugin instantiation. ([#2866](https://github.com/craftcms/cms/issues/2866))
- Fixed a bug where the table field's min rows setting would disable the add row button when it should not have. ([#2864](https://github.com/craftcms/cms/issues/2864))

## 3.0.6 - 2018-05-08

Expand Down
31 changes: 13 additions & 18 deletions src/web/assets/cp/dist/js/Craft.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! - 2018-05-05 */
/*! - 2018-05-10 */
(function($){

/** global: Craft */
Expand Down Expand Up @@ -12709,7 +12709,7 @@ Craft.EditableTable = Garnish.Base.extend(
}

if (this.settings.minRows && this.rowCount < this.settings.minRows) {
for (var i = 1; i < this.settings.minRows; i++) {
for (var i = this.rowCount; i < this.settings.minRows; i++) {
this.addRow()
}
}
Expand Down Expand Up @@ -12747,10 +12747,7 @@ Craft.EditableTable = Garnish.Base.extend(
}
},
updateAddRowButton: function() {
if (
(this.settings.maxRows && this.rowCount >= this.settings.maxRows) ||
(this.settings.minRows && this.rowCount < this.settings.minRows)
) {
if (this.settings.maxRows && this.rowCount >= this.settings.maxRows) {
this.$addRowBtn.css('opacity', '0.2');
this.$addRowBtn.css('pointer-events', 'none');
} else {
Expand All @@ -12762,31 +12759,29 @@ Craft.EditableTable = Garnish.Base.extend(
return (this.rowCount > this.settings.minRows);
},
deleteRow: function(row) {
if (this.settings.maxRows && this.settings.minRows) {
if (!this.canDeleteRow()) {
return;
}
if (!this.canDeleteRow()) {
return;
}

this.sorter.removeItems(row.$tr);
row.$tr.remove();

if (this.settings.minRows && this.settings.maxRows) {
this.rowCount--;
}
this.rowCount--;

this.updateAddRowButton();
// onDeleteRow callback
this.settings.onDeleteRow(row.$tr);
},
canAddRow: function() {
return (this.rowCount < this.settings.maxRows);
if (this.settings.maxRows) {
return (this.rowCount < this.settings.maxRows);
}

return true;
},
addRow: function() {
if (this.settings.minRows && this.settings.maxRows) {
if (!this.canAddRow()) {
return;
}
if (!this.canAddRow()) {
return;
}

var rowId = this.settings.rowIdPrefix + (this.biggestId + 1),
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/js/Craft.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/js/Craft.min.js.map

Large diffs are not rendered by default.

29 changes: 12 additions & 17 deletions src/web/assets/cp/src/js/EditableTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Craft.EditableTable = Garnish.Base.extend(
}

if (this.settings.minRows && this.rowCount < this.settings.minRows) {
for (var i = 1; i < this.settings.minRows; i++) {
for (var i = this.rowCount; i < this.settings.minRows; i++) {
this.addRow()
}
}
Expand Down Expand Up @@ -93,10 +93,7 @@ Craft.EditableTable = Garnish.Base.extend(
}
},
updateAddRowButton: function() {
if (
(this.settings.maxRows && this.rowCount >= this.settings.maxRows) ||
(this.settings.minRows && this.rowCount < this.settings.minRows)
) {
if (this.settings.maxRows && this.rowCount >= this.settings.maxRows) {
this.$addRowBtn.css('opacity', '0.2');
this.$addRowBtn.css('pointer-events', 'none');
} else {
Expand All @@ -108,31 +105,29 @@ Craft.EditableTable = Garnish.Base.extend(
return (this.rowCount > this.settings.minRows);
},
deleteRow: function(row) {
if (this.settings.maxRows && this.settings.minRows) {
if (!this.canDeleteRow()) {
return;
}
if (!this.canDeleteRow()) {
return;
}

this.sorter.removeItems(row.$tr);
row.$tr.remove();

if (this.settings.minRows && this.settings.maxRows) {
this.rowCount--;
}
this.rowCount--;

this.updateAddRowButton();
// onDeleteRow callback
this.settings.onDeleteRow(row.$tr);
},
canAddRow: function() {
return (this.rowCount < this.settings.maxRows);
if (this.settings.maxRows) {
return (this.rowCount < this.settings.maxRows);
}

return true;
},
addRow: function() {
if (this.settings.minRows && this.settings.maxRows) {
if (!this.canAddRow()) {
return;
}
if (!this.canAddRow()) {
return;
}

var rowId = this.settings.rowIdPrefix + (this.biggestId + 1),
Expand Down

0 comments on commit e28f739

Please sign in to comment.