saasufy-components 10.3.0 → 10.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/README.md +2 -0
- package/model-input.js +40 -14
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -669,6 +669,8 @@ Used for displaying and editing a single field of a model instance in realtime.
|
|
|
669
669
|
- `consumers`: This allows you to connect this `model-input` to other elements on your page. It 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 value of the `model-input` component in real-time. 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. Note that `model-input` elements of the `file` type are treated as write-only unless the `consumers` attribute is present.
|
|
670
670
|
- `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers.
|
|
671
671
|
- `show-error-message`: If this attribute is present, an error message will be displayed above the input if it fails to update the value.
|
|
672
|
+
- `error-consumers`: Sends error messages to other elements on your page instead of (or as well as) showing them next to the input. It takes the same list of selectors with optional attributes as `consumers`, in the format `element-selector:attribute-name`. This is useful when a message appearing beside the input would move the surrounding layout; the messages of a list of rows can be collected into a single area above the list, for example. Each input should be given a target of its own, since inputs which share one will overwrite each other's messages. The message is cleared (an empty string is sent) as soon as the input saves successfully. Can be used with or without `show-error-message`.
|
|
673
|
+
- `error-provider-template`: A template string within which the `{{value}}` of an error message can be injected before passing it to the elements named by `error-consumers`. Serves the same purpose for errors as `provider-template` does for values. Note that an error message is escaped before the template is applied, so markup in the message itself is shown as text while markup in the template is not.
|
|
672
674
|
- `options`: A comma-separated list of options to provide - This only works if the input type is `select`. Each option is in the format `label:type=value`; the `:type` and `=value` parts are optional. If the value is not specified, the label is used as the value. The type can be `string` (default), `number` or `boolean` and determines the type which will be saved to the model field when the option is selected; for example `options="30 min:number=30,1 hour:number=60"` will save the number `30` or `60` instead of the string `'30'` or `'60'`.
|
|
673
675
|
- `height`: Allows you to set the height of the inner `input` element programmatically.
|
|
674
676
|
- `default-value`: A default value to show the user if the underlying model field's value is null or undefined. Note that setting a default value will not affect the underlying model's value.
|
package/model-input.js
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
convertStringToFieldTypeValues,
|
|
7
7
|
getTypeCastFunction,
|
|
8
8
|
formatError,
|
|
9
|
-
renderTemplate
|
|
9
|
+
renderTemplate,
|
|
10
|
+
toSafeHTML
|
|
10
11
|
} from './utils.js';
|
|
11
12
|
import AGModel from '/node_modules/ag-model/ag-model.js';
|
|
12
13
|
|
|
@@ -35,6 +36,7 @@ class ModelInput extends SocketConsumer {
|
|
|
35
36
|
'placeholder',
|
|
36
37
|
'accept',
|
|
37
38
|
'consumers',
|
|
39
|
+
'error-consumers',
|
|
38
40
|
'show-error-message',
|
|
39
41
|
'model-type',
|
|
40
42
|
'model-id',
|
|
@@ -292,6 +294,40 @@ class ModelInput extends SocketConsumer {
|
|
|
292
294
|
}
|
|
293
295
|
}
|
|
294
296
|
|
|
297
|
+
reportError(messageContainerElement, errorMessage) {
|
|
298
|
+
if (messageContainerElement) {
|
|
299
|
+
messageContainerElement.textContent = errorMessage;
|
|
300
|
+
messageContainerElement.classList.add('error');
|
|
301
|
+
messageContainerElement.classList.remove('hidden');
|
|
302
|
+
}
|
|
303
|
+
this.updateErrorConsumerElements(errorMessage);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
clearError(messageContainerElement) {
|
|
307
|
+
if (messageContainerElement) {
|
|
308
|
+
messageContainerElement.textContent = '';
|
|
309
|
+
messageContainerElement.classList.remove('error');
|
|
310
|
+
messageContainerElement.classList.add('hidden');
|
|
311
|
+
}
|
|
312
|
+
this.updateErrorConsumerElements('');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// A consumer which is not given an attribute to write to has the message injected as HTML,
|
|
316
|
+
// and an error message can carry whatever the server quoted back, so the message is escaped
|
|
317
|
+
// first. Markup can still be introduced on purpose through the error-provider-template,
|
|
318
|
+
// which is applied after the escaping.
|
|
319
|
+
updateErrorConsumerElements(errorMessage) {
|
|
320
|
+
let errorConsumers = this.getAttribute('error-consumers');
|
|
321
|
+
if (!errorConsumers) return;
|
|
322
|
+
updateConsumerElements.call(
|
|
323
|
+
this,
|
|
324
|
+
errorConsumers,
|
|
325
|
+
toSafeHTML(errorMessage || ''),
|
|
326
|
+
this.getAttribute('error-provider-template'),
|
|
327
|
+
this.getAttribute('name')
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
295
331
|
verifyValue(fieldValue, optionList, inputElement, messageContainerElement) {
|
|
296
332
|
if (
|
|
297
333
|
optionList &&
|
|
@@ -301,11 +337,7 @@ class ModelInput extends SocketConsumer {
|
|
|
301
337
|
) {
|
|
302
338
|
inputElement.classList.add('error');
|
|
303
339
|
inputElement.classList.remove('success');
|
|
304
|
-
|
|
305
|
-
messageContainerElement.textContent = 'Invalid selection';
|
|
306
|
-
messageContainerElement.classList.add('error');
|
|
307
|
-
messageContainerElement.classList.remove('hidden');
|
|
308
|
-
}
|
|
340
|
+
this.reportError(messageContainerElement, 'Invalid selection');
|
|
309
341
|
}
|
|
310
342
|
}
|
|
311
343
|
|
|
@@ -336,17 +368,11 @@ class ModelInput extends SocketConsumer {
|
|
|
336
368
|
let errorStyleClass = 'error';
|
|
337
369
|
let successStyleClass = 'success';
|
|
338
370
|
let showErrorMessage = (fieldName, errorMessage) => {
|
|
339
|
-
|
|
340
|
-
messageContainerElement.textContent = errorMessage;
|
|
341
|
-
messageContainerElement.classList.add(errorStyleClass);
|
|
342
|
-
messageContainerElement.classList.remove('hidden');
|
|
371
|
+
this.reportError(messageContainerElement, errorMessage);
|
|
343
372
|
};
|
|
344
373
|
|
|
345
374
|
let hideErrorMessage = (fieldName) => {
|
|
346
|
-
|
|
347
|
-
messageContainerElement.textContent = '';
|
|
348
|
-
messageContainerElement.classList.remove(errorStyleClass);
|
|
349
|
-
messageContainerElement.classList.add('hidden');
|
|
375
|
+
this.clearError(messageContainerElement);
|
|
350
376
|
};
|
|
351
377
|
|
|
352
378
|
let consumers = this.getAttribute('consumers');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saasufy-components",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.5.0",
|
|
4
4
|
"description": "Components for Saasufy.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"ag-collection": "^6.0.0",
|
|
21
21
|
"ag-model": "^4.0.0",
|
|
22
|
-
"capitalisk-auth-client": "^2.
|
|
23
|
-
"socketcluster-client": "^
|
|
24
|
-
"uuid": "^
|
|
22
|
+
"capitalisk-auth-client": "^2.1.0",
|
|
23
|
+
"socketcluster-client": "^21.0.0",
|
|
24
|
+
"uuid": "^14.0.2"
|
|
25
25
|
},
|
|
26
26
|
"bugs": {
|
|
27
27
|
"url": "https://github.com/Saasufy/saasufy-components/issues"
|