@osimatic/helpers-js 1.5.10 → 1.5.12

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,9 +1,11 @@
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) {
8
+ form = toEl(form);
7
9
  let divParent = form.querySelector('input[type="date"][data-add_period_select_links]').parentElement;
8
10
  if (divParent.classList.contains('input-group')) {
9
11
  divParent = divParent.parentElement;
@@ -22,6 +24,7 @@ class InputPeriod {
22
24
  }
23
25
 
24
26
  static init(form) {
27
+ form = toEl(form);
25
28
  //console.log(form.querySelector('a.period_select_current_week'));
26
29
 
27
30
  const linkToday = form.querySelector('a.period_select_today');
@@ -136,6 +139,7 @@ class InputPeriod {
136
139
  class FormDate {
137
140
 
138
141
  static fillYearSelect(select, nbYearsBefore=5, nbYearsAfter=0) {
142
+ select = toEl(select);
139
143
  const currentDate = new Date();
140
144
  for (let year=currentDate.getUTCFullYear()-nbYearsBefore; year<=(currentDate.getUTCFullYear()+nbYearsAfter); year++) {
141
145
  select.insertAdjacentHTML('beforeend', '<option value="'+year+'">'+year+'</option>');
@@ -143,18 +147,21 @@ class FormDate {
143
147
  }
144
148
 
145
149
  static fillMonthSelect(select, locale) {
150
+ select = toEl(select);
146
151
  for (let month=1; month<=12; month++) {
147
152
  select.insertAdjacentHTML('beforeend', '<option value="'+month+'">'+DateTime.getMonthNameByMonth(month, locale).capitalize()+'</option>');
148
153
  }
149
154
  }
150
155
 
151
156
  static fillDayOfWeekSelect(select, locale) {
157
+ select = toEl(select);
152
158
  for (let dayOfWeek=1; dayOfWeek<=7; dayOfWeek++) {
153
159
  select.insertAdjacentHTML('beforeend', '<option value="'+dayOfWeek+'">'+DateTime.getDayNameByDayOfWeek(dayOfWeek, locale).capitalize()+'</option>');
154
160
  }
155
161
  }
156
162
 
157
163
  static initForm(form) {
164
+ form = toEl(form);
158
165
 
159
166
  function fillPeriodSelect(select) {
160
167
  Object.entries(FormDate.getPeriodList()).forEach(([idx, tabListPeriode]) => {
package/form_helper.js CHANGED
@@ -11,7 +11,8 @@ class FormHelper {
11
11
  FormHelper.buttonLoader(this, 'loading');
12
12
  FormHelper.hideFormErrors(form);
13
13
  if (typeof onSubmitCallback == 'function') {
14
- onSubmitCallback(form, submitButton);
14
+ const jq = wasJQuery && typeof $ !== 'undefined';
15
+ onSubmitCallback(jq ? $(form) : form, jq ? $(submitButton) : submitButton);
15
16
  }
16
17
  };
17
18
  return wasJQuery && typeof $ !== 'undefined' ? $(form) : form;
@@ -365,10 +366,11 @@ class FormHelper {
365
366
  // ------------------------------------------------------------
366
367
 
367
368
  static buttonLoader(button, action) {
369
+ const wasJQuery = button && button.jquery;
368
370
  button = toEl(button);
369
371
  if (action === 'start' || action === 'loading') {
370
372
  if (button.disabled) {
371
- return button;
373
+ return wasJQuery && typeof $ !== 'undefined' ? $(button) : button;
372
374
  }
373
375
  button.disabled = true;
374
376
  button.dataset.btnText = button.innerHTML;
@@ -390,7 +392,7 @@ class FormHelper {
390
392
  button.classList.remove('disabled');
391
393
  button.disabled = false;
392
394
  }
393
- return button;
395
+ return wasJQuery && typeof $ !== 'undefined' ? $(button) : button;
394
396
  }
395
397
 
396
398
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.5.10",
3
+ "version": "1.5.12",
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');