@cocreate/element-prototype 1.4.10 → 1.5.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [1.5.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.4.11...v1.5.0) (2023-03-15)
2
+
3
+
4
+ ### Features
5
+
6
+ * ability to use one checkbox as a boolean ([9dc3e5a](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/9dc3e5a0fa78a9a01a8e95759b48f63de69d111c))
7
+
8
+ ## [1.4.11](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.4.10...v1.4.11) (2023-02-01)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * bump dependencies ([3387cb7](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/3387cb7343808e48574ef00d3abc320a3d0cd048))
14
+
1
15
  ## [1.4.10](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.4.9...v1.4.10) (2023-02-01)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/element-prototype",
3
- "version": "1.4.10",
3
+ "version": "1.5.0",
4
4
  "description": "A simple element-prototype component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "element-prototype",
package/src/getValue.js CHANGED
@@ -21,18 +21,24 @@ const getValue = (element) => {
21
21
  let suffix = element.getAttribute('value-suffix') || "";
22
22
 
23
23
  if (element.type === "checkbox") {
24
- let el_name = element.getAttribute('name');
25
- let checkboxs = document.querySelectorAll(`input[type='checkbox'][name='${el_name}']`);
26
- if (checkboxs.length > 1) {
24
+ let inputs = [element]
25
+ let name = element.getAttribute('name');
26
+ if (name)
27
+ inputs = document.querySelectorAll(`input[type="${el.type}"][name="${name}"]`);
28
+
29
+
30
+ if (inputs.length > 1) {
27
31
  value = [];
28
- checkboxs.forEach(el => {
32
+ inputs.forEach(el => {
29
33
  if (el.checked)
30
34
  value.push(el.value);
31
35
  });
32
- }
33
- else {
34
- if (el.checked)
35
- value = el.value
36
+ } else {
37
+ if (element.checked)
38
+ value = element.value || 'true'
39
+ else if (!element.value)
40
+ value = 'false'
41
+
36
42
  }
37
43
  } else if (element.type === 'radio') {
38
44
  let name = element.getAttribute('name');
package/src/setValue.js CHANGED
@@ -26,13 +26,24 @@ const setValue = (el, value) => {
26
26
  if (isCrdt == "true" || el.type === 'file') return;
27
27
 
28
28
  if (el.type == 'checkbox') {
29
+ let inputs = [el]
29
30
  let name = el.getAttribute('name');
30
- let inputs = document.querySelectorAll(`input[type="${el.type}"][name="${name}"]`);
31
+ if (name)
32
+ inputs = document.querySelectorAll(`input[type="${el.type}"][name="${name}"]`);
33
+
31
34
  for (let i = 0; i < inputs.length; i++) {
32
- if (value.includes(inputs[i].value))
33
- inputs[i].checked = true;
34
- else
35
- inputs[i].checked = false;
35
+ if (inputs[i].value) {
36
+ if (value.includes(inputs[i].value))
37
+ inputs[i].checked = true;
38
+ else
39
+ inputs[i].checked = false;
40
+ } else {
41
+ if (value === 'true' || value === true || value === 'checked')
42
+ inputs[i].checked = true;
43
+ else
44
+ inputs[i].checked = false;
45
+
46
+ }
36
47
  }
37
48
  }
38
49
  else if (el.type === 'radio') {