Skip to content

Commit

Permalink
Fixed an error caused by deleting a column when there are mulitple co…
Browse files Browse the repository at this point in the history
…lumns and the deleted column is not the last one.
  • Loading branch information
Nav33d committed Jul 6, 2018
1 parent da56fc7 commit 4828fbd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## 2.0.0 - 2018-04-12
### Added
- Initial Craft CMS 3 release

## 2.0.1 - 2018-07-06
### Fixed
- Fixed an error caused by deleting a column when there are mulitple columns and the deleted column is not the last one.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "supercool/tablemaker",
"description": "A user-definable table field type for Craft CMS",
"type": "craft-plugin",
"version": "2.0.0",
"version": "2.0.1",
"keywords": [
"craft",
"cms",
Expand Down
30 changes: 11 additions & 19 deletions src/assetbundles/field/dist/js/tablemaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ Craft.TableMaker = Garnish.Base.extend(
this.getDataFromTables();

// prep table
var tableHtml = '<table id="'+this.rowsTableId+'" class="editable shadow-box">' +
'<thead>' +
var tableHtml = '<thead>' +
'<tr>';

// re-do columns of rowsTable
Expand All @@ -203,8 +202,14 @@ Craft.TableMaker = Garnish.Base.extend(

tableHtml += '<th class="header" colspan="2"></th>' +
'</tr>' +
'</thead>' +
'<tbody>';
'</thead>';

var $table = $('<table/>', {
id: this.rowsTableId,
'class': 'editable shadow-box'
}).append(tableHtml);

var $tbody = $('<tbody/>').appendTo($table);

// merge in the current rows content
for (var rowId in this.rows)
Expand All @@ -213,24 +218,11 @@ Craft.TableMaker = Garnish.Base.extend(
continue;
}

var myRow = Craft.EditableTable.createRow(rowId, this.columns, this.rowsTableName, this.rows[rowId]).get(0);
// We are doing this as Craft is not setting the value of textarea
var self = this;
$.each($(myRow).find('td textarea'), function(index, value) {
if ( self.rows[rowId]['col'+index] !== "" )
{
$(value).text(self.rows[rowId]['col'+index]);
}
});

tableHtml += myRow.outerHTML;
Craft.EditableTable.createRow(rowId, this.columns, this.rowsTableName, this.rows[rowId]).appendTo($tbody);
}

tableHtml += '</tbody>' +
'</table>';


this.rowsTable.$table.replaceWith(tableHtml);
this.rowsTable.$table.replaceWith($table);
this.rowsTable.destroy();
delete this.rowsTable;
this.initRowsTable(this.columns);
Expand Down
4 changes: 2 additions & 2 deletions src/fields/TableMakerField.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public function normalizeValue($value, ElementInterface $element = null)
$html .= '<tr>';

$i = 0;
foreach ($row as $cell) {
$align = $value['columns']['col'.$i]['align'] ?? $value['columns'][$i]['align'];
foreach ($row as $key => $cell) {
$align = $value['columns'][$key]['align'] ?? $value['columns'][$i]['align'];
$html .= '<td align="' . $align . '">' . $cell . '</td>';
$i++;
}
Expand Down

0 comments on commit 4828fbd

Please sign in to comment.