adt-js-components 1.3.2 → 1.3.4

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.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "JavaScript components for Nette framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,12 +21,12 @@ const init = (selector, path) => {
21
21
 
22
22
  if (path.includes('/')) {
23
23
  import('JsComponents/' + path + '/index.js').then(component => {
24
- component.default.run(componentsConfig[selector] || {}, $el);
24
+ component.default.run(componentsConfig[selector] || {});
25
25
  });
26
26
 
27
27
  } else {
28
28
  import('adt-js-components/src/' + path + '/index.js').then(component => {
29
- component.default.run(componentsConfig[selector] || {}, $el);
29
+ component.default.run(componentsConfig[selector] || {});
30
30
  });
31
31
  }
32
32
  });
@@ -10,6 +10,10 @@ function run(options) {
10
10
  // musí zde být defaultní jazyk "en", pokud zde nebyl a byla importována čeština.. tak se i bez poslání json params nastavila čeština
11
11
  $(this).select2($.extend({theme: 'bootstrap-5', language: "en"}, $(this).data('adt-select2') || {}));
12
12
  });
13
+
14
+ $el.find('[data-adt-select2]').on('change', function(e) {
15
+ Nette.toggleForm($(e.currentTarget).closest('form')[0], e.currentTarget);
16
+ });
13
17
  });
14
18
  }
15
19
 
@@ -21,10 +21,9 @@ function scrollToFirstError(form) {
21
21
  scrollParent.scrollBy({top: el.getBoundingClientRect().top - 100, behavior: 'smooth'});
22
22
  }
23
23
 
24
- function run(options) {
25
-
26
- function applyEventHandlers($el) {
27
- $el.find('input, textarea, select').on('input', function(e) {
24
+ function run(options, $el) {
25
+ function applyEventHandlers(el) {
26
+ $(this).find('input, textarea, select').on('input', function(e) {
28
27
  this.classList.remove('is-invalid');
29
28
  if (isList(this)) {
30
29
  $(this).parent().parent().find('.is-invalid').removeClass('is-invalid');
@@ -32,19 +31,23 @@ function run(options) {
32
31
  });
33
32
  }
34
33
 
35
- const observer = new MutationObserver(function(mutationsList, observer) {
36
- mutationsList.forEach(function(mutation) {
37
- if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
38
- $(mutation.addedNodes).each(function() {
39
- applyEventHandlers($(this));
34
+ $.nette.ext('live').after(function($el) {
35
+ $el.find('[data-adt-submit-form]').each(function(e) {
36
+ const observer = new MutationObserver(function(mutationsList, observer) {
37
+ mutationsList.forEach(function(mutation) {
38
+ if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
39
+ $(mutation.addedNodes).each(function() {
40
+ applyEventHandlers(this);
41
+ });
42
+ }
40
43
  });
41
- }
42
- });
43
- });
44
+ });
44
45
 
45
- observer.observe($el.get(0), { childList: true, subtree: true });
46
+ observer.observe(this, { childList: true, subtree: true });
46
47
 
47
- applyEventHandlers($el);
48
+ applyEventHandlers(this);
49
+ });
50
+ });
48
51
 
49
52
  if (typeof Nette !== "undefined") {
50
53
  Nette.showFormErrors = function(form, errors) {