adt-js-components 1.3.1 → 1.3.3

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.1",
3
+ "version": "1.3.3",
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
  });
@@ -1,11 +1,11 @@
1
1
  const Scrollparent = require("scrollparent");
2
2
 
3
3
  function isList(el) {
4
- return el.name.endsWith('[]') || el.type === 'radio';
4
+ return el.type === 'checkbox' && el.name.endsWith('[]') || el.type === 'radio';
5
5
  }
6
6
 
7
7
  function getErrorElementId(el) {
8
- return el.type === 'checkbox' && el.name.endsWith('[]') || el.type === 'radio'
8
+ return isList(el) ? el.id.split('-').slice(0, -1).join('-') : el.id;
9
9
  }
10
10
 
11
11
  function scrollToFirstError(form) {
@@ -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) {