From d89185ea96318c39e566ce59d0e91807a215da52 Mon Sep 17 00:00:00 2001 From: Charles Shin Date: Wed, 19 Jun 2019 14:21:37 -0700 Subject: [PATCH] DIV-944: Updated back button login to restore original data when edit is cancelled. --- edivorce/apps/core/static/js/main.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/edivorce/apps/core/static/js/main.js b/edivorce/apps/core/static/js/main.js index 1863c3fd..3ee36144 100755 --- a/edivorce/apps/core/static/js/main.js +++ b/edivorce/apps/core/static/js/main.js @@ -23,6 +23,13 @@ $(window).load(function(){ $('#questions_modal, #terms_modal').modal('show'); }); +// Temporarily store table row data. +var tempRowData = { + 'isNewRow': false, + 'el': null, + 'activeRow': null, +}; + $(function () { $('[data-toggle="tooltip"]').tooltip({ container: 'body', @@ -316,6 +323,7 @@ $(function () { $('.children-list').hide(); $('.fact-sheets').hide(); + tempRowData.isNewRow = true; initializeChildRowControls(newElement); }, customDeleteAction: function(){} @@ -470,10 +478,18 @@ $(function () { e.preventDefault(); returnToParent({persist: false}); - // Delete Empty row added to the children table. + // Delete the empty row added to the children table when adding new child. // Empty row will always be the last row of the table. - var $element = $('#claimant_children').find('tbody:first').find('tr:last'); - deleteAddedTableRow($element); + if (tempRowData.isNewRow) { + var $element = $('#claimant_children').find('tbody:first').find('tr:last'); + deleteAddedTableRow($element); + } else if (tempRowData.isNewRow === false && tempRowData.el !== null) { + // Restore original row data when edit is cancelled. + var $rows = $('#claimant_children').find('tbody:first').find(`tr[data-counter="${tempRowData.activeRow}"]`).find('.child-item-cell:not(.fact-sheet-button)'); + $rows.each(function(i, $row) { + $row.replaceWith(tempRowData.el[i]); + }); + } }); $('#claimant_children').each(function(){ @@ -799,6 +815,9 @@ var populateChildInputFields = function(element) { targetInput.filter("[value='" + $(this).text() + "']").prop('checked', true); } }); + tempRowData.isNewRow = false; + tempRowData.el = element.find('.child-item-cell:not(.fact-sheet-button)').clone(true, true); + tempRowData.activeRow = activeChildRow; }; var deleteChildData = function(settings, element) {