From 1b16dbcc072418792c389e10d8783dc1c3a8c020 Mon Sep 17 00:00:00 2001 From: ulferts Date: Wed, 11 Mar 2020 13:24:32 +0100 Subject: [PATCH] avoid double submit of form configuration The form configuration used to be submitted at least twice. In most cases, the first submit was canceled fast enough to not reach the backend. But if it was not canceled fast enough, the duplicate post lead to some errors when e.g. the referenced queries where already deleted. --- app/models/type/attribute_groups.rb | 1 - app/services/base_type_service.rb | 1 - app/views/types/form/_form_configuration.html.erb | 1 + .../types/type-form-configuration.component.ts | 15 ++++++++++++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/models/type/attribute_groups.rb b/app/models/type/attribute_groups.rb index 5873e53147..93bb4968af 100644 --- a/app/models/type/attribute_groups.rb +++ b/app/models/type/attribute_groups.rb @@ -136,7 +136,6 @@ module Type::AttributeGroups self.attribute_groups_objects = nil end - private def write_attribute_groups_objects diff --git a/app/services/base_type_service.rb b/app/services/base_type_service.rb index 448f4db1cf..0035393164 100644 --- a/app/services/base_type_service.rb +++ b/app/services/base_type_service.rb @@ -104,7 +104,6 @@ class BaseTypeService def transform_attribute_groups(groups) groups.map do |group| - if group['type'] == 'query' transform_query_group(group) else diff --git a/app/views/types/form/_form_configuration.html.erb b/app/views/types/form/_form_configuration.html.erb index 1abfcf013b..d851152ccc 100644 --- a/app/views/types/form/_form_configuration.html.erb +++ b/app/views/types/form/_form_configuration.html.erb @@ -89,6 +89,7 @@ See docs/COPYRIGHT.rdoc for more details.
<%= styled_button_tag t(@type.new_record? ? :button_create : :button_save), + data: { disable_with: t(@type.new_record? ? :button_create : :button_save) }, class: 'form-configuration--save -highlight -with-icon icon-checkmark' %>
diff --git a/frontend/src/app/modules/admin/types/type-form-configuration.component.ts b/frontend/src/app/modules/admin/types/type-form-configuration.component.ts index 5df24de52d..763c1fe712 100644 --- a/frontend/src/app/modules/admin/types/type-form-configuration.component.ts +++ b/frontend/src/app/modules/admin/types/type-form-configuration.component.ts @@ -79,9 +79,22 @@ export class TypeFormConfigurationComponent implements OnInit, OnDestroy { this.form = jQuery(this.element).closest('form'); this.submit = this.form.find('.form-configuration--save'); + // In the following we are triggering the form submit ourselves to work around + // a firefox shortcoming. But to avoid double submits which are sometimes not canceled fast + // enough, we need to memoize whether we have already submitted. + let submitted = false; + + this.form.on('submit', (event) => { + submitted = true; + }); + // Capture mousedown on button because firefox breaks blur on click this.submit.on('mousedown', (event) => { - setTimeout(() => this.form.trigger('submit'), 50); + setTimeout(() => { + if (!submitted) { + this.form.trigger('submit'); + } + }, 50); return true; });