@sitecore-jss/sitecore-jss-forms 12.0.2 → 12.0.5
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/dist/JssFormData.js +22 -9
- package/package.json +3 -3
- package/types/JssFormData.d.ts +5 -0
package/dist/JssFormData.js
CHANGED
|
@@ -22,9 +22,16 @@ var JssFormData = /** @class */ (function () {
|
|
|
22
22
|
};
|
|
23
23
|
/** Sets a key/value, removing any existing value(s) set for that key. */
|
|
24
24
|
JssFormData.prototype.set = function (key, value) {
|
|
25
|
-
this.
|
|
25
|
+
this.remove(key);
|
|
26
26
|
this.append(key, value);
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Removes any values for a given key from the form data.
|
|
30
|
+
* @param {string} key
|
|
31
|
+
*/
|
|
32
|
+
JssFormData.prototype.remove = function (key) {
|
|
33
|
+
this.data = this.data.filter(function (entry) { return entry.key !== key; });
|
|
34
|
+
};
|
|
28
35
|
/** Merges form data from a client-side state store (i.e. the user-specified values), overwriting any existing values for the keys */
|
|
29
36
|
JssFormData.prototype.mergeOverwritingExisting = function (values) {
|
|
30
37
|
var _this = this;
|
|
@@ -35,14 +42,20 @@ var JssFormData = /** @class */ (function () {
|
|
|
35
42
|
// we want to _set_ the first one to override anything existing,
|
|
36
43
|
// but _append_ anything after that to avoid overwriting our own values
|
|
37
44
|
if (Array.isArray(value)) {
|
|
38
|
-
value.
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
if (value.length === 0) {
|
|
46
|
+
// if empty array, ensure any pre-filled values are cleared (i.e. user de-selected these)
|
|
47
|
+
_this.remove(key);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
value.forEach(function (v, index) {
|
|
51
|
+
if (index === 0) {
|
|
52
|
+
_this.set(key, v);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
_this.append(key, v);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
46
59
|
}
|
|
47
60
|
else {
|
|
48
61
|
_this.set(key, value.toString());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-forms",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm run clean && tsc",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"typescript": "^3.6.3"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@sitecore-jss/sitecore-jss": "^12.0.
|
|
45
|
+
"@sitecore-jss/sitecore-jss": "^12.0.5"
|
|
46
46
|
},
|
|
47
47
|
"description": "",
|
|
48
48
|
"types": "types/index.d.ts",
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "e7503e862d40c254af2054c3e3fc97f9c6c78871"
|
|
50
50
|
}
|
package/types/JssFormData.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export declare class JssFormData {
|
|
|
9
9
|
append(key: string, value: string): void;
|
|
10
10
|
/** Sets a key/value, removing any existing value(s) set for that key. */
|
|
11
11
|
set(key: string, value: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Removes any values for a given key from the form data.
|
|
14
|
+
* @param {string} key
|
|
15
|
+
*/
|
|
16
|
+
remove(key: string): void;
|
|
12
17
|
/** Merges form data from a client-side state store (i.e. the user-specified values), overwriting any existing values for the keys */
|
|
13
18
|
mergeOverwritingExisting(values: {
|
|
14
19
|
[key: string]: string | string[] | boolean;
|