@cocreate/element-prototype 1.4.11 → 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 +7 -0
- package/package.json +1 -1
- package/src/getValue.js +14 -8
- package/src/setValue.js +16 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
## [1.4.11](https://github.com/CoCreate-app/CoCreate-element-prototype/compare/v1.4.10...v1.4.11) (2023-02-01)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/element-prototype",
|
|
3
|
-
"version": "1.
|
|
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
|
|
25
|
-
let
|
|
26
|
-
if (
|
|
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
|
-
|
|
32
|
+
inputs.forEach(el => {
|
|
29
33
|
if (el.checked)
|
|
30
34
|
value.push(el.value);
|
|
31
35
|
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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 (
|
|
33
|
-
inputs[i].
|
|
34
|
-
|
|
35
|
-
|
|
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') {
|