diff --git a/app/assets/javascripts/admin/index_utils/directives/obj_for_update.js.coffee b/app/assets/javascripts/admin/index_utils/directives/obj_for_update.js.coffee index 3ed4e6c98f..bf1edfdc20 100644 --- a/app/assets/javascripts/admin/index_utils/directives/obj_for_update.js.coffee +++ b/app/assets/javascripts/admin/index_utils/directives/obj_for_update.js.coffee @@ -4,15 +4,16 @@ angular.module("admin.indexUtils").directive "objForUpdate", (switchClass, pendi type: "@objForUpdate" attr: "@attrForUpdate" link: (scope, element, attrs) -> - scope.savedValue = scope.object()[scope.attr] + scope.savedValue = scope.object()[scope.attr] || "" scope.$watch "object().#{scope.attr}", (value) -> - if value == scope.savedValue + strValue = value || "" + if strValue == scope.savedValue pendingChanges.remove(scope.object().id, scope.attr) scope.clear() else scope.pending() - addPendingChange(scope.attr, value ? "") + addPendingChange(scope.attr, strValue) scope.reset = (value) -> scope.savedValue = value diff --git a/spec/system/admin/customers_spec.rb b/spec/system/admin/customers_spec.rb index 66ce746ecc..2033654f41 100644 --- a/spec/system/admin/customers_spec.rb +++ b/spec/system/admin/customers_spec.rb @@ -268,6 +268,10 @@ RSpec.describe 'Customers' do expect(page).to have_content 'You have unsaved changes' within("tr#c_#{customer1.id}") { fill_in "first_name", with: "John" } expect(page).not_to have_content 'You have unsaved changes' + within("tr#c_#{customer1.id}") { fill_in "code", with: "new-customer-code" } + expect(page).to have_content 'You have unsaved changes' + within("tr#c_#{customer1.id}") { fill_in "code", with: "" } + expect(page).not_to have_content 'You have unsaved changes' within "tr#c_#{customer1.id}" do expect(find_field('first_name').value).to eq 'John'