@osimatic/helpers-js 1.5.11 → 1.5.13

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/form_date.js CHANGED
@@ -1,10 +1,16 @@
1
+ const { toEl } = require('./util');
1
2
  const { DateTime } = require('./date_time');
2
3
 
3
4
  // input period de type : Du <input type="date" name="start_date" /> au <input type="date" name="end_date" />
4
5
  class InputPeriod {
5
6
 
6
7
  static addLinks(form) {
7
- let divParent = form.querySelector('input[type="date"][data-add_period_select_links]').parentElement;
8
+ form = toEl(form);
9
+ const input = form.querySelector('input[type="date"][data-add_period_select_links]');
10
+ if (!input) {
11
+ return;
12
+ }
13
+ let divParent = input.parentElement;
8
14
  if (divParent.classList.contains('input-group')) {
9
15
  divParent = divParent.parentElement;
10
16
  }
@@ -22,6 +28,7 @@ class InputPeriod {
22
28
  }
23
29
 
24
30
  static init(form) {
31
+ form = toEl(form);
25
32
  //console.log(form.querySelector('a.period_select_current_week'));
26
33
 
27
34
  const linkToday = form.querySelector('a.period_select_today');
@@ -136,6 +143,7 @@ class InputPeriod {
136
143
  class FormDate {
137
144
 
138
145
  static fillYearSelect(select, nbYearsBefore=5, nbYearsAfter=0) {
146
+ select = toEl(select);
139
147
  const currentDate = new Date();
140
148
  for (let year=currentDate.getUTCFullYear()-nbYearsBefore; year<=(currentDate.getUTCFullYear()+nbYearsAfter); year++) {
141
149
  select.insertAdjacentHTML('beforeend', '<option value="'+year+'">'+year+'</option>');
@@ -143,18 +151,21 @@ class FormDate {
143
151
  }
144
152
 
145
153
  static fillMonthSelect(select, locale) {
154
+ select = toEl(select);
146
155
  for (let month=1; month<=12; month++) {
147
156
  select.insertAdjacentHTML('beforeend', '<option value="'+month+'">'+DateTime.getMonthNameByMonth(month, locale).capitalize()+'</option>');
148
157
  }
149
158
  }
150
159
 
151
160
  static fillDayOfWeekSelect(select, locale) {
161
+ select = toEl(select);
152
162
  for (let dayOfWeek=1; dayOfWeek<=7; dayOfWeek++) {
153
163
  select.insertAdjacentHTML('beforeend', '<option value="'+dayOfWeek+'">'+DateTime.getDayNameByDayOfWeek(dayOfWeek, locale).capitalize()+'</option>');
154
164
  }
155
165
  }
156
166
 
157
167
  static initForm(form) {
168
+ form = toEl(form);
158
169
 
159
170
  function fillPeriodSelect(select) {
160
171
  Object.entries(FormDate.getPeriodList()).forEach(([idx, tabListPeriode]) => {
package/form_helper.js CHANGED
@@ -366,10 +366,11 @@ class FormHelper {
366
366
  // ------------------------------------------------------------
367
367
 
368
368
  static buttonLoader(button, action) {
369
+ const wasJQuery = button && button.jquery;
369
370
  button = toEl(button);
370
371
  if (action === 'start' || action === 'loading') {
371
372
  if (button.disabled) {
372
- return button;
373
+ return wasJQuery && typeof $ !== 'undefined' ? $(button) : button;
373
374
  }
374
375
  button.disabled = true;
375
376
  button.dataset.btnText = button.innerHTML;
@@ -391,7 +392,7 @@ class FormHelper {
391
392
  button.classList.remove('disabled');
392
393
  button.disabled = false;
393
394
  }
394
- return button;
395
+ return wasJQuery && typeof $ !== 'undefined' ? $(button) : button;
395
396
  }
396
397
 
397
398
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.5.11",
3
+ "version": "1.5.13",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "jest",
package/select_all.js CHANGED
@@ -29,6 +29,7 @@ class SelectAll {
29
29
  }
30
30
 
31
31
  static updateFormGroup(formGroup) {
32
+ formGroup = toEl(formGroup);
32
33
  const allCheckbox = formGroup.querySelectorAll('input[type="checkbox"]:not(.check_all)');
33
34
  const allCheckboxChecked = formGroup.querySelectorAll('input[type="checkbox"]:not(.check_all):checked');
34
35
  const lienSelectAll = formGroup.querySelector('a.check_all');
@@ -70,6 +71,7 @@ class SelectAll {
70
71
  }
71
72
 
72
73
  static updateTable(table) {
74
+ table = toEl(table);
73
75
  const allCheckbox = table.querySelectorAll('tbody input[type="checkbox"]');
74
76
  const allCheckboxChecked = table.querySelectorAll('tbody input[type="checkbox"]:checked');
75
77
  const checkboxSelectAll = table.querySelector('thead input.check_all');
@@ -107,6 +109,7 @@ class SelectAll {
107
109
  }
108
110
 
109
111
  static updateDiv(div) {
112
+ div = toEl(div);
110
113
  // 22/11/2021 : rajout :not(.check_all) sinon si toutes les cases sont coché, la case select all n'est pas coché à l'initialisation
111
114
  const allCheckbox = div.querySelectorAll('div.checkbox input[type="checkbox"]:not(.check_all), div.form-check input[type="checkbox"]:not(.check_all)');
112
115
  const allCheckboxChecked = div.querySelectorAll('div.checkbox input[type="checkbox"]:not(.check_all):checked, div.form-check input[type="checkbox"]:not(.check_all):checked');
@@ -651,6 +651,14 @@ describe('InputPeriod', () => {
651
651
  });
652
652
  });
653
653
 
654
+ test('should not throw when form has no input[data-add_period_select_links]', () => {
655
+ document.body.innerHTML = `<form><div><input type="date" /></div></form>`;
656
+ const form = document.querySelector('form');
657
+
658
+ expect(() => InputPeriod.addLinks(form)).not.toThrow();
659
+ expect(form.querySelector('.select_period_links')).toBeNull();
660
+ });
661
+
654
662
  describe('init', () => {
655
663
  test('should set up click handlers for all period links', () => {
656
664
  const linkSelectors = [