@osimatic/helpers-js 1.5.17 → 1.5.18

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.
Files changed (3) hide show
  1. package/form_helper.js +10 -10
  2. package/package.json +1 -1
  3. package/util.js +5 -1
package/form_helper.js CHANGED
@@ -1,4 +1,4 @@
1
- const { toEl } = require('./util');
1
+ const { toEl, toJquery } = require('./util');
2
2
 
3
3
  class FormHelper {
4
4
  static init(form, onSubmitCallback, submitButton=null) {
@@ -11,11 +11,10 @@ class FormHelper {
11
11
  FormHelper.buttonLoader(this, 'loading');
12
12
  FormHelper.hideFormErrors(form);
13
13
  if (typeof onSubmitCallback == 'function') {
14
- const jq = wasJQuery && typeof $ !== 'undefined';
15
- onSubmitCallback(jq ? $(form) : form, jq ? $(submitButton) : submitButton);
14
+ onSubmitCallback(wasJQuery ? toJquery(form) : form, wasJQuery ? toJquery(submitButton) : submitButton);
16
15
  }
17
16
  };
18
- return wasJQuery && typeof $ !== 'undefined' ? $(form) : form;
17
+ return wasJQuery ? toJquery(form) : form;
19
18
  }
20
19
 
21
20
  static reset(form, submitButton=null) {
@@ -29,7 +28,7 @@ class FormHelper {
29
28
  form.querySelectorAll('select.selectpicker').forEach(el => el.value = '');
30
29
  FormHelper.buttonLoader(submitButton, 'reset');
31
30
  FormHelper.hideFormErrors(form);
32
- return wasJQuery && typeof $ !== 'undefined' ? $(form) : form;
31
+ return wasJQuery ? toJquery(form) : form;
33
32
  }
34
33
 
35
34
  static populateForm(form, data) {
@@ -358,7 +357,7 @@ class FormHelper {
358
357
  button = toEl(button);
359
358
  if (action === 'start' || action === 'loading') {
360
359
  if (button.disabled) {
361
- return wasJQuery && typeof $ !== 'undefined' ? $(button) : button;
360
+ return wasJQuery ? toJquery(button) : button;
362
361
  }
363
362
  button.disabled = true;
364
363
  button.dataset.btnText = button.innerHTML;
@@ -380,7 +379,7 @@ class FormHelper {
380
379
  button.classList.remove('disabled');
381
380
  button.disabled = false;
382
381
  }
383
- return wasJQuery && typeof $ !== 'undefined' ? $(button) : button;
382
+ return wasJQuery ? toJquery(button) : button;
384
383
  }
385
384
 
386
385
 
@@ -403,6 +402,7 @@ class ArrayField {
403
402
  get_errors_callback: null,
404
403
 
405
404
  }) {
405
+ const wasJQuery = formGroupDiv && formGroupDiv.jquery;
406
406
  formGroupDiv = toEl(formGroupDiv);
407
407
  function isOptionDefined(optionName) {
408
408
  return typeof options[optionName] != 'undefined' && null !== options[optionName];
@@ -588,11 +588,11 @@ class ArrayField {
588
588
  let items = Array.isArray(item) ? item : [item];
589
589
 
590
590
  if (typeof options['format_entered_value_callback'] == 'function') {
591
- items = items.map(item => options['format_entered_value_callback'](item, divAdd));
591
+ items = items.map(item => options['format_entered_value_callback'](item, wasJQuery ? toJquery(divAdd) : divAdd));
592
592
  }
593
593
 
594
594
  if (typeof options['get_errors_callback'] == 'function') {
595
- const errors = options['get_errors_callback'](items, itemsList, divAdd);
595
+ const errors = options['get_errors_callback'](items, itemsList, wasJQuery ? toJquery(divAdd) : divAdd);
596
596
  if (null !== errors && errors.length) {
597
597
  displayErrors(divAdd, errors);
598
598
  return;
@@ -704,7 +704,7 @@ class ArrayField {
704
704
  onUpdateList();
705
705
 
706
706
  if (typeof options['init_callback'] == 'function') {
707
- options['init_callback'](formGroupDiv, onUpdateList, addItemsInList);
707
+ options['init_callback'](wasJQuery ? toJquery(formGroupDiv) : formGroupDiv, onUpdateList, addItemsInList);
708
708
  }
709
709
  }
710
710
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.5.17",
3
+ "version": "1.5.18",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "jest",
package/util.js CHANGED
@@ -18,4 +18,8 @@ function toEl(el) {
18
18
  return el && el.jquery ? el[0] : el;
19
19
  }
20
20
 
21
- module.exports = { sleep, refresh, toEl };
21
+ function toJquery(el) {
22
+ return typeof $ !== 'undefined' ? $(el) : el;
23
+ }
24
+
25
+ module.exports = { sleep, refresh, toEl, toJquery };