saasufy-components 3.4.1 → 3.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/collection-adder.js +48 -24
- package/package.json +1 -1
package/collection-adder.js
CHANGED
|
@@ -63,31 +63,47 @@ class CollectionAdder extends SocketConsumer {
|
|
|
63
63
|
|
|
64
64
|
let trimSpaces = this.hasAttribute('trim-spaces');
|
|
65
65
|
|
|
66
|
-
let newModelData = {
|
|
67
|
-
...this.modelFieldValues,
|
|
68
|
-
...radioData,
|
|
69
|
-
...Object.fromEntries(
|
|
70
|
-
[...this.querySelectorAll('.collection-adder-input')]
|
|
71
|
-
.filter(input => input.value !== '')
|
|
72
|
-
.map((input) => {
|
|
73
|
-
let fieldType = this.fieldTypes[input.name];
|
|
74
|
-
let Type = getTypeCastFunction(fieldType);
|
|
75
|
-
let value;
|
|
76
|
-
if (fieldType === 'checkbox') {
|
|
77
|
-
value = input.checked;
|
|
78
|
-
} else {
|
|
79
|
-
value = input.value;
|
|
80
|
-
}
|
|
81
|
-
let sanitizedValue = Type(value);
|
|
82
|
-
if (trimSpaces && typeof sanitizedValue === 'string') {
|
|
83
|
-
sanitizedValue = sanitizedValue.trim();
|
|
84
|
-
}
|
|
85
|
-
return [ input.name, sanitizedValue ];
|
|
86
|
-
})
|
|
87
|
-
)
|
|
88
|
-
};
|
|
89
|
-
|
|
90
66
|
try {
|
|
67
|
+
let newModelData = {
|
|
68
|
+
...this.modelFieldValues,
|
|
69
|
+
...radioData,
|
|
70
|
+
...Object.fromEntries(
|
|
71
|
+
await Promise.all(
|
|
72
|
+
[...this.querySelectorAll('.collection-adder-input')].filter(
|
|
73
|
+
input => input.value !== ''
|
|
74
|
+
)
|
|
75
|
+
.map(
|
|
76
|
+
async (input) => {
|
|
77
|
+
let fieldType = this.fieldTypes[input.name];
|
|
78
|
+
let Type = getTypeCastFunction(fieldType);
|
|
79
|
+
let value;
|
|
80
|
+
if (input.type === 'file' && input.files && input.files.length) {
|
|
81
|
+
let reader = new FileReader();
|
|
82
|
+
let readerLoadPromise = new Promise((resolve, reject) => {
|
|
83
|
+
reader.addEventListener('load', () => {
|
|
84
|
+
resolve(reader.result);
|
|
85
|
+
});
|
|
86
|
+
reader.addEventListener('error', () => {
|
|
87
|
+
reject(new Error('Failed to read file'));
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
reader.readAsDataURL(input.files[0]);
|
|
91
|
+
value = await readerLoadPromise;
|
|
92
|
+
} else if (fieldType === 'checkbox') {
|
|
93
|
+
value = input.checked;
|
|
94
|
+
} else {
|
|
95
|
+
value = input.value;
|
|
96
|
+
}
|
|
97
|
+
let sanitizedValue = Type(value);
|
|
98
|
+
if (trimSpaces && typeof sanitizedValue === 'string') {
|
|
99
|
+
sanitizedValue = sanitizedValue.trim();
|
|
100
|
+
}
|
|
101
|
+
return [ input.name, sanitizedValue ];
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
};
|
|
91
107
|
await this.collection.create(newModelData);
|
|
92
108
|
messageContainer.classList.add('success');
|
|
93
109
|
messageContainer.classList.remove('error');
|
|
@@ -250,6 +266,14 @@ class CollectionAdder extends SocketConsumer {
|
|
|
250
266
|
inputLabel
|
|
251
267
|
}"${extraAttributesString}></textarea>`
|
|
252
268
|
);
|
|
269
|
+
} else if (inputType === 'file') {
|
|
270
|
+
items.push(
|
|
271
|
+
`<input class="collection-adder-input" type="${
|
|
272
|
+
inputType
|
|
273
|
+
}" name="${
|
|
274
|
+
field
|
|
275
|
+
}"${extraAttributesString} />`
|
|
276
|
+
);
|
|
253
277
|
} else {
|
|
254
278
|
items.push(
|
|
255
279
|
`<input class="collection-adder-input" type="${
|