@cocreate/element-prototype 1.2.28 → 1.3.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,10 @@
1
+ # [1.3.0](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.2.28...v1.3.0) (2023-01-09)
2
+
3
+
4
+ ### Features
5
+
6
+ * improved handling of checkbox and radio ([b7444f2](https://github.com/CoCreate-app/CoCreate-element-prototype/commit/b7444f275a6cad77d6d1678e823ca654b3e4df63))
7
+
1
8
  ## [1.2.28](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.2.27...v1.2.28) (2023-01-09)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/element-prototype",
3
- "version": "1.2.28",
3
+ "version": "1.3.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
@@ -22,7 +22,7 @@ const getValue = (element) => {
22
22
 
23
23
  if (element.type === "checkbox") {
24
24
  let el_name = element.getAttribute('name');
25
- let checkboxs = document.querySelectorAll(`input[type=checkbox][name='${el_name}']`);
25
+ let checkboxs = document.querySelectorAll(`input[type='checkbox'][name='${el_name}']`);
26
26
  if (checkboxs.length > 1) {
27
27
  value = [];
28
28
  checkboxs.forEach(el => {
@@ -34,7 +34,10 @@ const getValue = (element) => {
34
34
  if (el.checked)
35
35
  value = el.value
36
36
  }
37
- }
37
+ } else if (element.type === 'radio') {
38
+ let name = element.getAttribute('name');
39
+ value = document.querySelector(`input[name="${name}"]:checked`).value
40
+ }
38
41
  else if (element.type === "number") {
39
42
  value = Number(value);
40
43
  }
package/src/setValue.js CHANGED
@@ -26,11 +26,13 @@ const setValue = (el, value) => {
26
26
  if (isCrdt == "true" || el.type === 'file') return;
27
27
 
28
28
  if (el.type == 'checkbox') {
29
- if (value.includes(el.value)) {
30
- el.checked = true;
31
- }
32
- else {
33
- el.checked = false;
29
+ let name = el.getAttribute('name');
30
+ let inputs = document.querySelectorAll(`input[type="${el.type}"][name="${name}"]`);
31
+ 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;
34
36
  }
35
37
  }
36
38
  else if (el.type === 'radio') {