@osimatic/helpers-js 1.5.24 → 1.5.26

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/chartjs.js CHANGED
@@ -42,7 +42,12 @@ class Chartjs {
42
42
 
43
43
  static createStackedChart(chartDiv, chartData, title=null, options={}) {
44
44
  Chartjs.init();
45
+
45
46
  chartDiv = toEl(chartDiv);
47
+ if (!chartDiv) {
48
+ return;
49
+ }
50
+
46
51
  chartDiv.innerHTML = '';
47
52
  new Chart(chartDiv.getContext("2d"), deepmerge({
48
53
  type: "bar",
@@ -93,7 +98,12 @@ class Chartjs {
93
98
 
94
99
  static createBarChart(chartDiv, chartData, title=null, options={}) {
95
100
  Chartjs.init();
101
+
96
102
  chartDiv = toEl(chartDiv);
103
+ if (!chartDiv) {
104
+ return;
105
+ }
106
+
97
107
  chartDiv.innerHTML = '';
98
108
  new Chart(chartDiv.getContext("2d"), deepmerge({
99
109
  type: "bar",
@@ -151,6 +161,10 @@ class Chartjs {
151
161
  Chartjs.init();
152
162
 
153
163
  chartDiv = toEl(chartDiv);
164
+ if (!chartDiv) {
165
+ return;
166
+ }
167
+
154
168
  chartDiv.innerHTML = '';
155
169
  new Chart(chartDiv.getContext("2d"), deepmerge({
156
170
  type: "line",
@@ -204,6 +218,10 @@ class Chartjs {
204
218
  Chartjs.init();
205
219
 
206
220
  chartDiv = toEl(chartDiv);
221
+ if (!chartDiv) {
222
+ return;
223
+ }
224
+
207
225
  chartDiv.innerHTML = '';
208
226
  new Chart(chartDiv.getContext("2d"), deepmerge({
209
227
  type: "doughnut",
package/count_down.js CHANGED
@@ -4,16 +4,16 @@ class CountDown {
4
4
 
5
5
  static init(div, options = {}) {
6
6
  div = toEl(div);
7
+ if (!div) {
8
+ return;
9
+ }
10
+
7
11
  const {
8
12
  onRefreshData,
9
13
  labelNextUpdate = 'Prochaine mise à jour',
10
14
  labelDoUpdate = 'Mettre à jour',
11
15
  } = options;
12
16
 
13
- if (!div) {
14
- return;
15
- }
16
-
17
17
  div.insertAdjacentHTML('beforeend', '<div class="count_down_title">'+labelNextUpdate+'</div>');
18
18
  div.insertAdjacentHTML('beforeend', '<div class="count_down_progress"><div class="count_down_current"></div></div>');
19
19
  div.insertAdjacentHTML('beforeend', '<div class="count_down_text"></div>');
@@ -5,6 +5,10 @@ class DetailsSubArray {
5
5
 
6
6
  static initDetailsLink(table, options = {}) {
7
7
  table = toEl(table);
8
+ if (!table) {
9
+ return;
10
+ }
11
+
8
12
  const {
9
13
  onSuccess,
10
14
  onError,
package/file.js CHANGED
@@ -105,6 +105,10 @@ class Img {
105
105
 
106
106
  static initImg(div) {
107
107
  div = toEl(div);
108
+ if (!div) {
109
+ return;
110
+ }
111
+
108
112
  div.querySelectorAll('.asynchronously_img').forEach(img => {
109
113
  Img.loadImgUrl(img.dataset.url, img);
110
114
  });
package/form_date.js CHANGED
@@ -6,6 +6,10 @@ class InputPeriod {
6
6
 
7
7
  static addLinks(form) {
8
8
  form = toEl(form);
9
+ if (!form) {
10
+ return;
11
+ }
12
+
9
13
  const input = form.querySelector('input[type="date"][data-add_period_select_links]');
10
14
  if (!input) {
11
15
  return;
@@ -29,6 +33,9 @@ class InputPeriod {
29
33
 
30
34
  static init(form) {
31
35
  form = toEl(form);
36
+ if (!form) {
37
+ return;
38
+ }
32
39
  //console.log(form.querySelector('a.period_select_current_week'));
33
40
 
34
41
  const linkToday = form.querySelector('a.period_select_today');
@@ -144,6 +151,9 @@ class FormDate {
144
151
 
145
152
  static fillYearSelect(select, nbYearsBefore=5, nbYearsAfter=0) {
146
153
  select = toEl(select);
154
+ if (!select) {
155
+ return;
156
+ }
147
157
  const currentDate = new Date();
148
158
  for (let year=currentDate.getUTCFullYear()-nbYearsBefore; year<=(currentDate.getUTCFullYear()+nbYearsAfter); year++) {
149
159
  select.insertAdjacentHTML('beforeend', '<option value="'+year+'">'+year+'</option>');
@@ -152,6 +162,9 @@ class FormDate {
152
162
 
153
163
  static fillMonthSelect(select, locale) {
154
164
  select = toEl(select);
165
+ if (!select) {
166
+ return;
167
+ }
155
168
  for (let month=1; month<=12; month++) {
156
169
  select.insertAdjacentHTML('beforeend', '<option value="'+month+'">'+DateTime.getMonthNameByMonth(month, locale).capitalize()+'</option>');
157
170
  }
@@ -159,6 +172,9 @@ class FormDate {
159
172
 
160
173
  static fillDayOfWeekSelect(select, locale) {
161
174
  select = toEl(select);
175
+ if (!select) {
176
+ return;
177
+ }
162
178
  for (let dayOfWeek=1; dayOfWeek<=7; dayOfWeek++) {
163
179
  select.insertAdjacentHTML('beforeend', '<option value="'+dayOfWeek+'">'+DateTime.getDayNameByDayOfWeek(dayOfWeek, locale).capitalize()+'</option>');
164
180
  }
@@ -166,6 +182,9 @@ class FormDate {
166
182
 
167
183
  static initForm(form) {
168
184
  form = toEl(form);
185
+ if (!form) {
186
+ return;
187
+ }
169
188
 
170
189
  function fillPeriodSelect(select) {
171
190
  Object.entries(FormDate.getPeriodList()).forEach(([idx, tabListPeriode]) => {
package/form_helper.js CHANGED
@@ -3,9 +3,16 @@ const { toEl, toJquery } = require('./util');
3
3
  class FormHelper {
4
4
  static init(form, onSubmitCallback, submitButton=null) {
5
5
  const wasJQuery = form && form.jquery;
6
- form = toEl(form); submitButton = toEl(submitButton);
6
+ form = toEl(form);
7
+ if (!form) {
8
+ return;
9
+ }
10
+
7
11
  FormHelper.reset(form, submitButton);
8
- submitButton = null != submitButton ? submitButton : form.querySelector('button[name="validate"]');
12
+ submitButton = null != submitButton ? toEl(submitButton) : form.querySelector('button[name="validate"]');
13
+ if (!submitButton) {
14
+ return wasJQuery ? toJquery(form) : form;
15
+ }
9
16
  submitButton.onclick = function(e) {
10
17
  e.preventDefault();
11
18
  FormHelper.buttonLoader(this, 'loading');
@@ -19,8 +26,12 @@ class FormHelper {
19
26
 
20
27
  static reset(form, submitButton=null) {
21
28
  const wasJQuery = form && form.jquery;
22
- form = toEl(form); submitButton = toEl(submitButton);
23
- submitButton = null != submitButton ? submitButton : form.querySelector('button[name="validate"]');
29
+ form = toEl(form);
30
+ if (!form) {
31
+ return;
32
+ }
33
+
34
+ submitButton = null != submitButton ? toEl(submitButton) : form.querySelector('button[name="validate"]');
24
35
  form.querySelectorAll('input[name]:not([type="checkbox"]):not([type="radio"]), select:not(.selectpicker), textarea').forEach(el => {
25
36
  el.value = '';
26
37
  el.onchange = null;
@@ -33,6 +44,10 @@ class FormHelper {
33
44
 
34
45
  static populateForm(form, data) {
35
46
  form = toEl(form);
47
+ if (!form) {
48
+ return;
49
+ }
50
+
36
51
  const employeesDisplayType = form.querySelector('[name="employees_display_type"][value="NONE"]');
37
52
  if (employeesDisplayType) employeesDisplayType.checked = true; //todo à retirer
38
53
 
@@ -72,12 +87,15 @@ class FormHelper {
72
87
 
73
88
  static getFormData(form) {
74
89
  form = toEl(form);
90
+ if (!form) {
91
+ return null;
92
+ }
75
93
  return new FormData(form);
76
94
  }
77
95
 
78
96
  static getDataFromFormData(formData) {
79
97
  let data = {};
80
- for(let pair of formData.entries()) {
98
+ for (let pair of formData.entries()) {
81
99
  //console.log(pair[0]+ ', '+ pair[1]);
82
100
  data[pair[0]] = pair[1];
83
101
  }
@@ -86,6 +104,9 @@ class FormHelper {
86
104
 
87
105
  static getFormDataQueryString(form) {
88
106
  form = toEl(form);
107
+ if (!form) {
108
+ return null;
109
+ }
89
110
  return new URLSearchParams(new FormData(form)).toString();
90
111
  }
91
112
 
@@ -97,7 +118,7 @@ class FormHelper {
97
118
 
98
119
  static getInputValue(input) {
99
120
  input = toEl(input);
100
- if (typeof input == 'undefined' || input == null) {
121
+ if (!input) {
101
122
  return null;
102
123
  }
103
124
  let value = input.value;
@@ -109,11 +130,18 @@ class FormHelper {
109
130
 
110
131
  static getLinesOfTextarea(textarea) {
111
132
  textarea = toEl(textarea);
133
+ if (!textarea) {
134
+ return null;
135
+ }
112
136
  return textarea.value.replace(/(\r\n|\n|\r)/g, "\n").split("\n").filter(word => word.length > 0);
113
137
  }
114
138
 
115
139
  static setOnInputChange(input, callback, doneTypingInterval=700) {
116
140
  input = toEl(input);
141
+ if (!input) {
142
+ return null;
143
+ }
144
+
117
145
  // setup before functions
118
146
  let typingTimer; // timer identifier
119
147
 
@@ -141,6 +169,10 @@ class FormHelper {
141
169
 
142
170
  static resetSelectOption(form, selectName) {
143
171
  form = toEl(form);
172
+ if (!form) {
173
+ return null;
174
+ }
175
+
144
176
  form.querySelectorAll('select[name="'+selectName+'"] option').forEach(o => {
145
177
  o.disabled = false;
146
178
  o.selected = false;
@@ -148,24 +180,48 @@ class FormHelper {
148
180
  }
149
181
  static setSelectedSelectOption(form, selectName, optionValue) {
150
182
  form = toEl(form);
183
+ if (!form) {
184
+ return;
185
+ }
186
+
151
187
  const opt = form.querySelector('select[name="'+selectName+'"] option[value="'+optionValue+'"]');
152
- if (opt) opt.selected = true;
188
+ if (opt) {
189
+ opt.selected = true;
190
+ }
153
191
  }
154
192
  static setSelectedSelectOptions(form, selectName, optionValues) {
155
193
  form = toEl(form);
194
+ if (!form) {
195
+ return;
196
+ }
197
+
156
198
  optionValues.forEach(id => FormHelper.setSelectedSelectOption(form, selectName, id));
157
199
  }
158
200
  static disableSelectOption(form, selectName, optionValue) {
159
201
  form = toEl(form);
202
+ if (!form) {
203
+ return;
204
+ }
205
+
160
206
  const opt = form.querySelector('select[name="'+selectName+'"] option[value="'+optionValue+'"]');
161
- if (opt) opt.disabled = true;
207
+ if (opt) {
208
+ opt.disabled = true;
209
+ }
162
210
  }
163
211
  static disableSelectOptions(form, selectName, optionValues) {
164
212
  form = toEl(form);
213
+ if (!form) {
214
+ return;
215
+ }
216
+
165
217
  optionValues.forEach(id => FormHelper.disableSelectOption(form, selectName, id));
166
218
  }
167
219
  static countSelectOptions(form, selectName) {
168
220
  form = toEl(form);
221
+ if (!form) {
222
+ return null;
223
+ }
224
+
169
225
  return form.querySelectorAll('select[name="'+selectName+'"] option:not([disabled])').length;
170
226
  }
171
227
 
@@ -199,6 +255,9 @@ class FormHelper {
199
255
 
200
256
  static initTypeFields(form) {
201
257
  form = toEl(form);
258
+ if (!form) {
259
+ return;
260
+ }
202
261
 
203
262
  // Show/Hide password
204
263
  form.querySelectorAll('input[type="password"]').forEach(inputEl => {
@@ -223,6 +282,9 @@ class FormHelper {
223
282
 
224
283
  static hideField(inputOrSelect) {
225
284
  inputOrSelect = toEl(inputOrSelect);
285
+ if (!inputOrSelect) {
286
+ return;
287
+ }
226
288
  inputOrSelect.closest('.form-group')?.classList.add('hide');
227
289
  }
228
290
 
@@ -281,6 +343,9 @@ class FormHelper {
281
343
  static hideFormErrors(form) {
282
344
  const wasJQuery = form && form.jquery;
283
345
  form = toEl(form);
346
+ if (!form) {
347
+ return null;
348
+ }
284
349
  form.querySelectorAll('div.form_errors').forEach(el => el.remove());
285
350
  return wasJQuery ? toJquery(form) : form;
286
351
  }
@@ -315,6 +380,10 @@ class FormHelper {
315
380
 
316
381
  static displayFormErrorsFromText(form, errorLabels, errorWrapperDiv=null) {
317
382
  form = toEl(form); errorWrapperDiv = toEl(errorWrapperDiv);
383
+ if (!form) {
384
+ return;
385
+ }
386
+
318
387
  let errorDiv = '<div class="alert alert-danger form_errors">'+errorLabels+'</div>';
319
388
 
320
389
  if (null != errorWrapperDiv) {
@@ -356,6 +425,10 @@ class FormHelper {
356
425
  static buttonLoader(button, action) {
357
426
  const wasJQuery = button && button.jquery;
358
427
  button = toEl(button);
428
+ if (!button) {
429
+ return null;
430
+ }
431
+
359
432
  if (action === 'start' || action === 'loading') {
360
433
  if (button.disabled) {
361
434
  return wasJQuery ? toJquery(button) : button;
@@ -405,6 +478,9 @@ class ArrayField {
405
478
  }) {
406
479
  const wasJQuery = formGroupDiv && formGroupDiv.jquery;
407
480
  formGroupDiv = toEl(formGroupDiv);
481
+ if (!formGroupDiv) {
482
+ return;
483
+ }
408
484
  function isOptionDefined(optionName) {
409
485
  return typeof options[optionName] != 'undefined' && null !== options[optionName];
410
486
  }
@@ -713,6 +789,9 @@ class ArrayField {
713
789
  class EditValue {
714
790
  static init(valueDiv, onSubmitCallback, getInputCallback) {
715
791
  valueDiv = toEl(valueDiv);
792
+ if (!valueDiv) {
793
+ return;
794
+ }
716
795
  const link = document.createElement('a');
717
796
  link.href = '#';
718
797
  link.className = 'text-warning';
package/google_charts.js CHANGED
@@ -45,6 +45,10 @@ class GoogleCharts {
45
45
 
46
46
  static draw(div, options) {
47
47
  div = toEl(div);
48
+ if (!div) {
49
+ return;
50
+ }
51
+
48
52
  const {
49
53
  chart_type: chartType,
50
54
  title: title,
@@ -21,6 +21,10 @@ class ImportFromCsv {
21
21
 
22
22
  static initForm(div, options = {}) {
23
23
  div = toEl(div);
24
+ if (!div) {
25
+ return;
26
+ }
27
+
24
28
  const {
25
29
  importColumns,
26
30
  requestImportData,
@@ -74,7 +78,7 @@ class ImportFromCsv {
74
78
  }
75
79
 
76
80
  const hasHeader = formUpload.querySelectorAll('input[name="header"][value="1"]:checked').length;
77
- const encoding = formUpload.querySelector('select[name="encoding"]').value;
81
+ const encoding = formUpload.querySelector('select[name="encoding"]')?.value;
78
82
 
79
83
  Papa.parse(fileInput.files[0], {
80
84
  header: hasHeader,
@@ -175,6 +179,10 @@ class ImportFromCsv {
175
179
 
176
180
  static displayData(divResult, data, header, formMatching) {
177
181
  divResult = toEl(divResult);
182
+ if (!divResult) {
183
+ return;
184
+ }
185
+
178
186
  let table = divResult.querySelector('table');
179
187
  if (!table) {
180
188
  divResult.insertAdjacentHTML('beforeend', '<table class="table table-sm table-bordered"></table>');
package/location.js CHANGED
@@ -306,6 +306,9 @@ class Country {
306
306
  class PostalAddress {
307
307
  static setAutocomplete(input, onPlaceChanged) {
308
308
  input = toEl(input);
309
+ if (!input) {
310
+ return;
311
+ }
309
312
  const autocomplete = new google.maps.places.Autocomplete(
310
313
  input,
311
314
  {types: ['geocode']}
package/media.js CHANGED
@@ -10,6 +10,10 @@ class AudioMedia {
10
10
 
11
11
  static initPlayLinks(div) {
12
12
  div = toEl(div);
13
+ if (!div) {
14
+ return;
15
+ }
16
+
13
17
  // Affiche un lecteur audio
14
18
  div.querySelectorAll('.play_link').forEach(link => {
15
19
  link.addEventListener('click', function(e) {
@@ -128,6 +132,10 @@ class AudioMedia {
128
132
  class VideoMedia {
129
133
  static initPlayPauseClick(videoElement) {
130
134
  videoElement = toEl(videoElement);
135
+ if (!videoElement) {
136
+ return;
137
+ }
138
+
131
139
  videoElement.addEventListener('click', function(e) {
132
140
  // handle click if not Firefox (Firefox supports this feature natively)
133
141
  if (typeof InstallTrigger === 'undefined') {
@@ -5,8 +5,15 @@ const { toEl } = require('./util');
5
5
  class MultiFilesInput {
6
6
  static init(fileInput, setFilesList, nbMaxFiles, maxFileSize) {
7
7
  fileInput = toEl(fileInput);
8
+ if (!fileInput) {
9
+ return;
10
+ }
11
+
8
12
  let filesList = [];
9
13
  const formGroup = fileInput.closest('.form-group');
14
+ if (!formGroup) {
15
+ return;
16
+ }
10
17
 
11
18
  if (!formGroup.querySelector('.multi_files_input_dropzone')) {
12
19
  fileInput.insertAdjacentHTML('afterend', `
@@ -29,12 +29,12 @@ class MultipleActionInTable {
29
29
  // Peut être appelé après l'initialisation DataTable.
30
30
  static init(table, options = {}) {
31
31
  table = toEl(table);
32
- const { cellSelector = 'select', imgArrow = '' } = options;
33
-
34
32
  if (!table || !table.classList.contains('table-action_multiple')) {
35
33
  return;
36
34
  }
37
35
 
36
+ const { cellSelector = 'select', imgArrow = '' } = options;
37
+
38
38
  let divBtn = MultipleActionInTable.getDivBtn(table);
39
39
  if (divBtn == null) {
40
40
  return;
@@ -145,6 +145,10 @@ class MultipleActionInDivList {
145
145
  // init checkbox
146
146
  static init(contentDiv, options = {}) {
147
147
  contentDiv = toEl(contentDiv);
148
+ if (!contentDiv) {
149
+ return;
150
+ }
151
+
148
152
  const { imgArrow = '' } = options;
149
153
 
150
154
  let buttonsDiv = MultipleActionInDivList.getButtonsDiv(contentDiv);
@@ -457,6 +457,7 @@ class OsmMap {
457
457
 
458
458
  constructor(mapContainer, options={}) {
459
459
  mapContainer = toEl(mapContainer);
460
+
460
461
  this.markers = [];
461
462
  this.locations = [];
462
463
  this.tempSelection = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.5.24",
3
+ "version": "1.5.26",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "jest",
package/paging.js CHANGED
@@ -3,24 +3,23 @@ const { toEl } = require('./util');
3
3
 
4
4
  class Pagination {
5
5
  static paginateCards(div, nbItemsPerPage) {
6
- div = toEl(div);
7
6
  Pagination.paginate(div, div.querySelectorAll('.pagination_item'), nbItemsPerPage, null);
8
7
  }
9
8
 
10
9
  static paginateTable(table, select=null) {
11
- table = toEl(table); select = toEl(select);
12
10
  Pagination.paginate(table, table.querySelectorAll('tbody tr:not(.hide)'), parseInt(table.dataset.max_rows), select);
13
11
  }
14
12
 
15
13
  static paginate(div, items, nbItemsPerPage, select=null, labelDisplayAll=null) {
16
- div = toEl(div); select = toEl(select);
17
- let maxItems = nbItemsPerPage;
18
-
14
+ div = toEl(div);
19
15
  if (!div) {
20
16
  return;
21
17
  }
22
18
 
23
- if (select != null) {
19
+ let maxItems = nbItemsPerPage;
20
+
21
+ select = select != null ? toEl(select) : null;
22
+ if (select) {
24
23
  if (!select.children.length) {
25
24
  const opt0 = document.createElement('option');
26
25
  opt0.value = '0';
@@ -53,6 +52,11 @@ class Pagination {
53
52
  }
54
53
 
55
54
  static initPaginationDiv(div, onTop) {
55
+ div = toEl(div);
56
+ if (!div) {
57
+ return;
58
+ }
59
+
56
60
  const ul = document.createElement('ul');
57
61
  ul.className = 'pagination';
58
62
 
@@ -137,6 +141,7 @@ class Navigation {
137
141
  if (!a) {
138
142
  return;
139
143
  }
144
+
140
145
  let ulNav = a.closest('.nav');
141
146
  if (!ulNav) {
142
147
  return;
@@ -164,9 +169,11 @@ class Navigation {
164
169
  }
165
170
 
166
171
  static showTab(a) {
167
- if (typeof bootstrap == 'undefined') {
172
+ a = toEl(a);
173
+ if (!a || typeof bootstrap == 'undefined') {
168
174
  return;
169
175
  }
176
+
170
177
  let tab = new bootstrap.Tab(a);
171
178
  tab.show();
172
179
  }
package/select_all.js CHANGED
@@ -39,6 +39,7 @@ class SelectAll {
39
39
  if (!formGroup) {
40
40
  return;
41
41
  }
42
+
42
43
  const allCheckbox = formGroup.querySelectorAll('input[type="checkbox"]:not(.check_all)');
43
44
  const allCheckboxChecked = formGroup.querySelectorAll('input[type="checkbox"]:not(.check_all):checked');
44
45
  const lienSelectAll = formGroup.querySelector('a.check_all');
@@ -60,6 +61,7 @@ class SelectAll {
60
61
  if (!table) {
61
62
  return;
62
63
  }
64
+
63
65
  const inputCheckAll = table.querySelector('tr input.check_all');
64
66
  if (!inputCheckAll) {
65
67
  return;
@@ -87,6 +89,7 @@ class SelectAll {
87
89
  if (!table) {
88
90
  return;
89
91
  }
92
+
90
93
  const allCheckbox = table.querySelectorAll('tbody input[type="checkbox"]');
91
94
  const allCheckboxChecked = table.querySelectorAll('tbody input[type="checkbox"]:checked');
92
95
  const checkboxSelectAll = table.querySelector('thead input.check_all');
@@ -103,6 +106,7 @@ class SelectAll {
103
106
  if (!contentDiv) {
104
107
  return;
105
108
  }
109
+
106
110
  contentDiv.querySelectorAll('input.check_all').forEach(inputCheckAll => {
107
111
  const div = inputCheckAll.closest('div.checkbox_with_check_all');
108
112
 
@@ -137,6 +141,7 @@ class SelectAll {
137
141
  if (!div) {
138
142
  return;
139
143
  }
144
+
140
145
  // 22/11/2021 : rajout :not(.check_all) sinon si toutes les cases sont coché, la case select all n'est pas coché à l'initialisation
141
146
  const allCheckbox = div.querySelectorAll('div.checkbox input[type="checkbox"]:not(.check_all), div.form-check input[type="checkbox"]:not(.check_all)');
142
147
  const allCheckboxChecked = div.querySelectorAll('div.checkbox input[type="checkbox"]:not(.check_all):checked, div.form-check input[type="checkbox"]:not(.check_all):checked');
package/sortable_list.js CHANGED
@@ -3,6 +3,10 @@ const { toEl } = require('./util');
3
3
  class SortableList {
4
4
  static init(sortableList, clientYOffset=0) {
5
5
  sortableList = toEl(sortableList);
6
+ if (!sortableList) {
7
+ return;
8
+ }
9
+
6
10
  sortableList.querySelectorAll('[draggable="true"]').forEach(item => {
7
11
  item.addEventListener('dragstart', () => {
8
12
  // Adding dragging class to an item after a delay
@@ -182,6 +182,11 @@ describe('FormDate', () => {
182
182
  mockSelect = { insertAdjacentHTML: jest.fn() };
183
183
  });
184
184
 
185
+ test('should do nothing if element does not exist', () => {
186
+ expect(() => FormDate.fillYearSelect(null)).not.toThrow();
187
+ expect(() => FormDate.fillYearSelect(undefined)).not.toThrow();
188
+ });
189
+
185
190
  test('should fill select with years from 5 years before to current year', () => {
186
191
  FormDate.fillYearSelect(mockSelect);
187
192
 
@@ -259,6 +264,11 @@ describe('FormDate', () => {
259
264
  }
260
265
  });
261
266
 
267
+ test('should do nothing if element does not exist', () => {
268
+ expect(() => FormDate.fillMonthSelect(null)).not.toThrow();
269
+ expect(() => FormDate.fillMonthSelect(undefined)).not.toThrow();
270
+ });
271
+
262
272
  test('should fill select with 12 months', () => {
263
273
  FormDate.fillMonthSelect(mockSelect, 'fr');
264
274
 
@@ -281,6 +291,11 @@ describe('FormDate', () => {
281
291
  }
282
292
  });
283
293
 
294
+ test('should do nothing if element does not exist', () => {
295
+ expect(() => FormDate.fillDayOfWeekSelect(null)).not.toThrow();
296
+ expect(() => FormDate.fillDayOfWeekSelect(undefined)).not.toThrow();
297
+ });
298
+
284
299
  test('should fill select with 7 days of week', () => {
285
300
  FormDate.fillDayOfWeekSelect(mockSelect, 'fr');
286
301