saasufy-components 3.10.1 → 3.12.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/README.md +2 -2
- package/app-router.js +1 -1
- package/collection-adder.js +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -253,7 +253,7 @@ A form component for inserting data into collections.
|
|
|
253
253
|
<collection-adder
|
|
254
254
|
collection-type="Product"
|
|
255
255
|
collection-fields="name,brand,qty"
|
|
256
|
-
model-values="categoryName=electronics"
|
|
256
|
+
model-values="categoryName=electronics,isNew:boolean=true"
|
|
257
257
|
submit-button-label="Create"
|
|
258
258
|
trim-spaces
|
|
259
259
|
></collection-adder>
|
|
@@ -263,7 +263,7 @@ A form component for inserting data into collections.
|
|
|
263
263
|
|
|
264
264
|
- `collection-type` (required): Specifies the type of collection to add the resource to when the form is submitted. This should match a `Model` available in your Saasufy service.
|
|
265
265
|
- `collection-fields`: A comma-separated list of fields from the `Model` to display as input elements inside the form for the user to fill in. Each field name in this list can optionally be followed by an input element type after a `:` character. For example `collection-fields="qty:number, size:select(small,medium,large)` will create one input element with `type="number"` and one with `type=select` with options `small`, `medium` or `large`. To make a select field optional, you can prefix the list of options with a comma; e.g. `size:select(,small,medium,large)`.
|
|
266
|
-
- `model-values`: An optional list of key-value pairs in the format `field1=value1,field2=value2` to add to the newly created resource alongside the values collected from the user via the form.
|
|
266
|
+
- `model-values`: An optional list of key-value pairs in the format `field1=value1,field2=value2` to add to the newly created resource alongside the values collected from the user via the form. For non-string values, the type should be provided in the format `fieldName:type=value`; supported types are `string`, `number` and `boolean`.
|
|
267
267
|
- `submit-button-label`: Text to display on the submit button. If not specified, defaults to `Submit`.
|
|
268
268
|
- `hide-submit-button`: Adding this attribute will hide the submit button from the form.
|
|
269
269
|
- `success-message`: A message to show the user if the resource has been successfully added to the collection after submitting the form.
|
package/app-router.js
CHANGED
|
@@ -34,7 +34,7 @@ export class AppRouter extends SocketConsumer {
|
|
|
34
34
|
let pageTemplate = this.pages[route];
|
|
35
35
|
let allowPartialMatch = pageTemplate.hasAttribute('partial-route');
|
|
36
36
|
return {
|
|
37
|
-
regExp: new RegExp(
|
|
37
|
+
regExp: new RegExp(`${allowPartialMatch ? '' : '^'}${route.replace(/\/:[^\/]+/g, '/([^/]*)').replace(/\//g, '\\/')}${allowPartialMatch ? '' : '$'}`, 'g'),
|
|
38
38
|
route,
|
|
39
39
|
params: [ ...route.matchAll(/:[^\/]*/g) ].map(paramMatch => paramMatch[0].replace(':', ''))
|
|
40
40
|
};
|
package/collection-adder.js
CHANGED
|
@@ -154,6 +154,7 @@ class CollectionAdder extends SocketConsumer {
|
|
|
154
154
|
|
|
155
155
|
let {
|
|
156
156
|
fieldNames: modelFieldNames,
|
|
157
|
+
fieldTypes: modelFieldTypes,
|
|
157
158
|
fieldValues: modelFieldValues
|
|
158
159
|
} = convertStringToFieldParams(this.getAttribute('model-values'));
|
|
159
160
|
|
|
@@ -174,7 +175,17 @@ class CollectionAdder extends SocketConsumer {
|
|
|
174
175
|
autocorrect ? ` autocorrect="${autocorrect}"` : ''
|
|
175
176
|
}`;
|
|
176
177
|
|
|
177
|
-
this.modelFieldValues =
|
|
178
|
+
this.modelFieldValues = Object.fromEntries(
|
|
179
|
+
Object.entries(modelFieldValues).map(([key, value]) => {
|
|
180
|
+
if (modelFieldTypes[key] === 'boolean') {
|
|
181
|
+
return [ key, value !== 'false' && value !== '' ];
|
|
182
|
+
}
|
|
183
|
+
if (modelFieldTypes[key] === 'number') {
|
|
184
|
+
return [ key, Number(value) ];
|
|
185
|
+
}
|
|
186
|
+
return [ key, value ];
|
|
187
|
+
})
|
|
188
|
+
);
|
|
178
189
|
|
|
179
190
|
if (this.collection) this.collection.destroy();
|
|
180
191
|
|