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.
pull/8130/head
ulferts 5 years ago
parent 53e656ed4c
commit 1b16dbcc07
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 1
      app/models/type/attribute_groups.rb
  2. 1
      app/services/base_type_service.rb
  3. 1
      app/views/types/form/_form_configuration.html.erb
  4. 15
      frontend/src/app/modules/admin/types/type-form-configuration.component.ts

@ -136,7 +136,6 @@ module Type::AttributeGroups
self.attribute_groups_objects = nil
end
private
def write_attribute_groups_objects

@ -104,7 +104,6 @@ class BaseTypeService
def transform_attribute_groups(groups)
groups.map do |group|
if group['type'] == 'query'
transform_query_group(group)
else

@ -89,6 +89,7 @@ See docs/COPYRIGHT.rdoc for more details.
<div class="grid-block">
<div class="generic-table--action-buttons">
<%= 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' %>
</div>
</div>

@ -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;
});

Loading…
Cancel
Save