saasufy-components 10.1.0 → 10.2.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 +3 -3
- package/collection-adder-form.js +15 -5
- package/collection-adder.js +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -457,7 +457,7 @@ This component is a simplified version of the `collection-adder-form` component
|
|
|
457
457
|
- `autocapitalize`: Can be set to `off` to disable auto-capitalization of the first input character on mobile devices.
|
|
458
458
|
- `autocorrect`: Can be set to `off` to disable auto-correction of input on mobile devices.
|
|
459
459
|
- `show-field-errors`: If this attribute exists on the element, then granular error messages will be shown above each corresponding input element instead of a single form-level error message.
|
|
460
|
-
- `trim-spaces`: If this attribute exists on the element, then leading and trailing spaces will be trimmed from each input element's value before submitting the form.
|
|
460
|
+
- `trim-spaces`: If this attribute exists on the element, then leading and trailing spaces will be trimmed from each input element's value before submitting the form. It can optionally be set to a comma-separated list of field names such as `trim-spaces="name,brand"`; in this case, only the values of the listed fields will be trimmed and all others will be left as they are. If the attribute has no value, then all input values will be trimmed.
|
|
461
461
|
- `reset-status-on-submit`: If this attribute exists, then the current message and any field errors will be cleared as soon as the form is submitted, instead of when the outcome of the submit is known. By default, the previous status is kept on screen until the insert either succeeds or fails and is then replaced within a single frame; this avoids the form flickering (shrinking and then growing again) when the same error occurs on consecutive submits.
|
|
462
462
|
- `consumers`: This allows you to connect this `collection-adder` to other elements on your page. It should be used in conjunction with the `provider-template` attribute. The `consumers` attribute takes a list of selectors with optional attributes to target in the format `element-selector:attribute-name`. For example `.my-input:value` will find all elements with a `my-input` class and update their `value` attributes with the output of the `collection-adder` component on submit. You can specify multiple selectors separated by commas such as `.my-input,my-div`; in this case, because attribute names are not specified, values will be injected into the `value` attribute (for input elements) or into the `innerHTML` property (for other kinds of elements). The default attribute/property depends on the element type.
|
|
463
463
|
- `success-consumers`: Same as the `consumers` attribute but the target elements are only updated if insertion was a success.
|
|
@@ -498,7 +498,7 @@ This component is similar to the `collection-adder` component except that it req
|
|
|
498
498
|
- `computable-model-values`: If this attribute exists on the element, then the `model-values` attribute will be re-computed before the form is submitted; this may be useful if the `model-values` attribute contains expressions which need to be updated before submitting.
|
|
499
499
|
- `success-message`: A message to show the user if the resource has been successfully added to the collection after submitting the form.
|
|
500
500
|
- `show-field-errors`: If this attribute exists on the element, then granular error messages will be shown above each corresponding input element instead of a single form-level error message.
|
|
501
|
-
- `trim-spaces`: If this attribute exists on the element, then leading and trailing spaces will be trimmed from each input element's value before submitting the form.
|
|
501
|
+
- `trim-spaces`: If this attribute exists on the element, then leading and trailing spaces will be trimmed from each input element's value before submitting the form. It can optionally be set to a comma-separated list of input names such as `trim-spaces="name,brand"`; in this case, only the values of the listed inputs will be trimmed and all others will be left as they are. If the attribute has no value, then all input values will be trimmed.
|
|
502
502
|
- `auto-reset-hidden-inputs`: If this attribute exists, then `hidden` input elements which are inside the `collection-adder-form` will be cleared along with other input fields. By default, `hidden` input elements are not cleared when the form is reset.
|
|
503
503
|
- `reset-status-on-submit`: If this attribute exists, then the current message and any field errors will be cleared as soon as the form is submitted, instead of when the outcome of the submit is known. By default, the previous status is kept on screen until the insert either succeeds or fails and is then replaced within a single frame; this avoids the form flickering (shrinking and then growing again) when the same error occurs on consecutive submits.
|
|
504
504
|
- `disable-submit-on-enter-key`: If this attribute exists, then the form will not submit when the enter key is pressed.
|
|
@@ -511,7 +511,7 @@ This component is similar to the `collection-adder` component except that it req
|
|
|
511
511
|
**Attributes of slotted input, select, textarea... elements**
|
|
512
512
|
|
|
513
513
|
- `name` (required): This must correspond to a field name on the model specified via the `collection-type` attribute of the `collection-adder-form`.
|
|
514
|
-
- `output-type`: An optional type to cast the value of the input element into when the form is submitted.
|
|
514
|
+
- `output-type`: An optional type to cast the value of the input element into when the form is submitted; supported types are `string` (default), `number` and `boolean`. This is especially useful for `select` elements as their values are always strings by default; for example `<select name="duration" output-type="number">` will submit the number `30` instead of the string `'30'`. If not specified, the value is cast based on the element's own type.
|
|
515
515
|
|
|
516
516
|
### collection-deleter
|
|
517
517
|
|
package/collection-adder-form.js
CHANGED
|
@@ -59,7 +59,15 @@ class CollectionAdderForm extends SocketConsumer {
|
|
|
59
59
|
this.clearStatus();
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// The trim-spaces attribute can either be empty (in which case spaces are
|
|
63
|
+
// trimmed from all input values) or it can hold a comma-separated list of
|
|
64
|
+
// input names to restrict trimming to those specific inputs.
|
|
62
65
|
let trimSpaces = this.hasAttribute('trim-spaces');
|
|
66
|
+
let trimSpacesInputNames = trimSpaces ?
|
|
67
|
+
(this.getAttribute('trim-spaces') || '')
|
|
68
|
+
.split(',')
|
|
69
|
+
.map(inputName => inputName.trim())
|
|
70
|
+
.filter(inputName => inputName) : [];
|
|
63
71
|
|
|
64
72
|
let inputElements = this.getAllInputElements();
|
|
65
73
|
let outputValue;
|
|
@@ -92,10 +100,8 @@ class CollectionAdderForm extends SocketConsumer {
|
|
|
92
100
|
} else {
|
|
93
101
|
inputType = input.type;
|
|
94
102
|
}
|
|
95
|
-
let
|
|
96
|
-
|
|
97
|
-
input.getAttribute('output-type') : inputType
|
|
98
|
-
);
|
|
103
|
+
let outputType = input.getAttribute('output-type');
|
|
104
|
+
let Type = getTypeCastFunction(outputType || inputType);
|
|
99
105
|
let value;
|
|
100
106
|
if (inputType === 'file' && input.files && input.files.length) {
|
|
101
107
|
let reader = new FileReader();
|
|
@@ -115,7 +121,11 @@ class CollectionAdderForm extends SocketConsumer {
|
|
|
115
121
|
value = input.value;
|
|
116
122
|
}
|
|
117
123
|
let sanitizedValue = Type(value);
|
|
118
|
-
|
|
124
|
+
let shouldTrimSpaces = trimSpaces && (
|
|
125
|
+
!trimSpacesInputNames.length ||
|
|
126
|
+
trimSpacesInputNames.includes(input.name)
|
|
127
|
+
);
|
|
128
|
+
if (shouldTrimSpaces && typeof sanitizedValue === 'string') {
|
|
119
129
|
sanitizedValue = sanitizedValue.trim();
|
|
120
130
|
}
|
|
121
131
|
return [ input.name, sanitizedValue ];
|
package/collection-adder.js
CHANGED
|
@@ -70,7 +70,16 @@ class CollectionAdder extends SocketConsumer {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
// The trim-spaces attribute can either be empty (in which case spaces are
|
|
74
|
+
// trimmed from all input values) or it can hold a comma-separated list of
|
|
75
|
+
// field names to restrict trimming to those specific inputs.
|
|
73
76
|
let trimSpaces = this.hasAttribute('trim-spaces');
|
|
77
|
+
let trimSpacesFieldNames = trimSpaces ?
|
|
78
|
+
(this.getAttribute('trim-spaces') || '')
|
|
79
|
+
.split(',')
|
|
80
|
+
.map(fieldName => fieldName.trim())
|
|
81
|
+
.filter(fieldName => fieldName) : [];
|
|
82
|
+
|
|
74
83
|
let outputValue;
|
|
75
84
|
|
|
76
85
|
let modelValues = this.getAttribute('model-values');
|
|
@@ -116,7 +125,11 @@ class CollectionAdder extends SocketConsumer {
|
|
|
116
125
|
value = input.value;
|
|
117
126
|
}
|
|
118
127
|
let sanitizedValue = Type(value);
|
|
119
|
-
|
|
128
|
+
let shouldTrimSpaces = trimSpaces && (
|
|
129
|
+
!trimSpacesFieldNames.length ||
|
|
130
|
+
trimSpacesFieldNames.includes(input.name)
|
|
131
|
+
);
|
|
132
|
+
if (shouldTrimSpaces && typeof sanitizedValue === 'string') {
|
|
120
133
|
sanitizedValue = sanitizedValue.trim();
|
|
121
134
|
}
|
|
122
135
|
return [ input.name, sanitizedValue ];
|