adt-js-components 1.9.5 → 1.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adt-js-components",
3
- "version": "1.9.5",
3
+ "version": "1.9.6",
4
4
  "description": "JavaScript components for Nette framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -4,7 +4,11 @@ async function run(options) {
4
4
  if ($el.is('button, input[type="button"], input[type="submit"]')) {
5
5
  $el.on('click', sendNetteAjax);
6
6
  } else if ($el.is('input:not([type="button"]):not([type="submit"]), select, textarea')) {
7
- $el.on('input', sendNetteAjax);
7
+ let debounceTimer;
8
+ $el.on('input', function(e) {
9
+ clearTimeout(debounceTimer);
10
+ debounceTimer = setTimeout(() => sendNetteAjax(e), 500);
11
+ });
8
12
  }
9
13
  }
10
14
 
@@ -110,6 +110,14 @@ function run(options) {
110
110
 
111
111
  $.nette.ext("submitForm", {
112
112
  before: function (xhr, settings) {
113
+ if (settings.nette && settings.nette.el) {
114
+ const pendingXhr = settings.nette.el.data('pendingXhr');
115
+ if (pendingXhr) {
116
+ pendingXhr.abort();
117
+ }
118
+ settings.nette.el.data('pendingXhr', xhr);
119
+ }
120
+
113
121
  if (settings.nette && settings.nette.form && settings.nette.form.attr('data-adt-submit-form') !== undefined) {
114
122
  let beforeCallback = settings.nette.el.attr('data-adt-submit-form-before-callback');
115
123
  if (beforeCallback) {
@@ -156,6 +164,10 @@ function run(options) {
156
164
  }
157
165
  },
158
166
  complete: function (xhr, status, settings) {
167
+ if (settings.nette && settings.nette.el) {
168
+ settings.nette.el.data('pendingXhr', null);
169
+ }
170
+
159
171
  // if there are errors we will scroll to first of them
160
172
  if (settings.nette && settings.nette.form && settings.nette.form.attr('data-adt-submit-form') !== undefined && settings.nette.form.find('.alert-danger, .is-invalid').length > 0) {
161
173
  scrollToFirstError(settings.nette.form);