@osimatic/helpers-js 1.5.12 → 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
@@ -6,7 +6,11 @@ class InputPeriod {
6
6
 
7
7
  static addLinks(form) {
8
8
  form = toEl(form);
9
- let divParent = form.querySelector('input[type="date"][data-add_period_select_links]').parentElement;
9
+ const input = form.querySelector('input[type="date"][data-add_period_select_links]');
10
+ if (!input) {
11
+ return;
12
+ }
13
+ let divParent = input.parentElement;
10
14
  if (divParent.classList.contains('input-group')) {
11
15
  divParent = divParent.parentElement;
12
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.5.12",
3
+ "version": "1.5.13",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -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 = [