@osimatic/helpers-js 1.5.17 → 1.5.19

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.
@@ -56,10 +56,6 @@ class TelephoneNumber {
56
56
  TelephoneNumber.localCountryCode = countryCode;
57
57
  }
58
58
 
59
- static setIntlTelInputUtilsPath(path) {
60
- TelephoneNumber.intlTelInputUtilsPath = path;
61
- }
62
-
63
59
  static getCountryIsoCode(phoneNumber, localCountryIsoCode=TelephoneNumber.localCountryCode) {
64
60
  try {
65
61
  const number = libphonenumber.parsePhoneNumber(phoneNumber, localCountryIsoCode.toUpperCase());
@@ -172,12 +168,10 @@ class TelephoneNumber {
172
168
 
173
169
  static setIntlTelInput(input, placeholderNumberType) {
174
170
  TelephoneNumber.localCountryCode = typeof TelephoneNumber.localCountryCode != 'undefined' ? TelephoneNumber.localCountryCode : null;
175
- TelephoneNumber.intlTelInputUtilsPath = typeof TelephoneNumber.intlTelInputUtilsPath != 'undefined' ? TelephoneNumber.intlTelInputUtilsPath : null;
176
171
 
177
172
  return intlTelInputLib(input[0], {
178
173
  initialCountry: null != TelephoneNumber.localCountryCode ? TelephoneNumber.localCountryCode.toLowerCase() : null, // depuis version 19.x, le code pays doit être en minuscule
179
174
  placeholderNumberType: placeholderNumberType || 'FIXED_LINE_OR_MOBILE',
180
- utilsScript: TelephoneNumber.intlTelInputUtilsPath
181
175
  });
182
176
  }
183
177
 
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/location.js CHANGED
@@ -17,6 +17,9 @@ class Country {
17
17
 
18
18
  static fillCountrySelect(select, defaultValue=null, countriesList=null, addNoneValue=false, noneLabel='- Aucun -') {
19
19
  select = toEl(select);
20
+ if (!select) {
21
+ return;
22
+ }
20
23
  if (select.children.length === 0) {
21
24
  if (addNoneValue) {
22
25
  select.insertAdjacentHTML('beforeend', '<option value="">'+noneLabel+'</option>');
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.19",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "jest",
package/paging.js CHANGED
@@ -133,7 +133,14 @@ class Pagination {
133
133
 
134
134
  class Navigation {
135
135
  static activateTab(a) {
136
+ a = toEl(a);
137
+ if (!a) {
138
+ return;
139
+ }
136
140
  let ulNav = a.closest('.nav');
141
+ if (!ulNav) {
142
+ return;
143
+ }
137
144
  let tabContent = ulNav.parentElement.querySelector('.tab-content');
138
145
 
139
146
  ulNav.querySelectorAll('a.nav-link').forEach(navLink => {
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 };