@unicef-polymer/etools-form-builder 1.0.3 → 2.0.0-rc.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/form-attachments-popup/form-attachments-popup.d.ts +10 -2
- package/dist/form-attachments-popup/form-attachments-popup.js +12 -3
- package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +0 -5
- package/dist/form-attachments-popup/form-attachments-popup.tpl.js +0 -5
- package/dist/form-fields/abstract-field-base.class.d.ts +28 -0
- package/dist/form-fields/{base-field.js → abstract-field-base.class.js} +64 -38
- package/dist/form-fields/field-renderer-component.d.ts +20 -0
- package/dist/form-fields/field-renderer-component.js +249 -0
- package/dist/form-fields/index.d.ts +11 -5
- package/dist/form-fields/index.js +11 -5
- package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -0
- package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +208 -0
- package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -0
- package/dist/form-fields/repeatable-fields/repeatable-base-field.js +123 -0
- package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -0
- package/dist/form-fields/repeatable-fields/repeatable-number-field.js +66 -0
- package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -0
- package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +108 -0
- package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -0
- package/dist/form-fields/repeatable-fields/repeatable-text-field.js +53 -0
- package/dist/form-fields/single-fields/attachment-field.d.ts +16 -0
- package/dist/form-fields/single-fields/attachment-field.js +97 -0
- package/dist/form-fields/single-fields/base-field.d.ts +11 -0
- package/dist/form-fields/single-fields/base-field.js +57 -0
- package/dist/form-fields/single-fields/boolean-field.d.ts +8 -0
- package/dist/form-fields/single-fields/boolean-field.js +49 -0
- package/dist/form-fields/{number-field.d.ts → single-fields/number-field.d.ts} +1 -0
- package/dist/form-fields/single-fields/number-field.js +66 -0
- package/dist/form-fields/{scale-field.d.ts → single-fields/scale-field.d.ts} +4 -2
- package/dist/form-fields/{scale-field.js → single-fields/scale-field.js} +21 -5
- package/dist/form-fields/{text-field.d.ts → single-fields/text-field.d.ts} +0 -0
- package/dist/form-fields/{wide-field.js → single-fields/text-field.js} +29 -26
- package/dist/form-groups/form-abstract-group.d.ts +12 -12
- package/dist/form-groups/form-abstract-group.js +141 -114
- package/dist/form-groups/form-card.d.ts +1 -0
- package/dist/form-groups/form-card.js +32 -3
- package/dist/form-groups/form-collapsed-card.d.ts +3 -1
- package/dist/form-groups/form-collapsed-card.js +31 -7
- package/dist/index.d.ts +3 -14
- package/dist/index.js +3 -19
- package/dist/lib/additional-components/confirmation-dialog.d.ts +16 -0
- package/dist/lib/additional-components/confirmation-dialog.js +65 -0
- package/dist/lib/additional-components/etools-fb-card.js +7 -0
- package/dist/lib/styles/attachments.styles.js +5 -2
- package/dist/lib/styles/form-builder-card.styles.js +8 -3
- package/dist/lib/styles/page-layout-styles.js +1 -1
- package/dist/lib/types/form-builder.interfaces.d.ts +2 -2
- package/dist/lib/types/form-builder.types.d.ts +8 -2
- package/dist/lib/utils/validations.helper.d.ts +3 -3
- package/dist/lib/utils/validations.helper.js +7 -7
- package/package.json +3 -2
- package/dist/form-fields/base-field.d.ts +0 -20
- package/dist/form-fields/custom-elements.define.d.ts +0 -1
- package/dist/form-fields/custom-elements.define.js +0 -11
- package/dist/form-fields/number-field.js +0 -43
- package/dist/form-fields/text-field.js +0 -39
- package/dist/form-fields/wide-field.d.ts +0 -11
- package/dist/form-groups/custom-elements.define.d.ts +0 -1
- package/dist/form-groups/custom-elements.define.js +0 -9
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import '@unicef-polymer/etools-upload/etools-upload';
|
|
8
|
+
import { BaseField } from './base-field';
|
|
9
|
+
import { AttachmentsHelper } from '../../form-attachments-popup';
|
|
10
|
+
import { html, customElement } from 'lit-element';
|
|
11
|
+
import { fireEvent } from '../../lib/utils/fire-custom-event';
|
|
12
|
+
import { SharedStyles } from '../../lib/styles/shared-styles';
|
|
13
|
+
import { AttachmentsStyles } from '../../lib/styles/attachments.styles';
|
|
14
|
+
let AttachmentField = class AttachmentField extends BaseField {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
this.computedPath = [];
|
|
18
|
+
}
|
|
19
|
+
get uploadUrl() {
|
|
20
|
+
return AttachmentsHelper.uploadUrl;
|
|
21
|
+
}
|
|
22
|
+
get jwtLocalStorageKey() {
|
|
23
|
+
return AttachmentsHelper.jwtLocalStorageKey;
|
|
24
|
+
}
|
|
25
|
+
controlTemplate() {
|
|
26
|
+
return html `
|
|
27
|
+
<!-- Upload button -->
|
|
28
|
+
<etools-upload
|
|
29
|
+
class="with-padding"
|
|
30
|
+
activate-offline
|
|
31
|
+
.uploadedFileInfo="${this.value}"
|
|
32
|
+
?readonly="${this.isReadonly}"
|
|
33
|
+
@upload-finished="${({ detail }) => this.attachmentsUploaded(detail)}"
|
|
34
|
+
@delete-file="${() => this.valueChanged(null)}"
|
|
35
|
+
.endpointInfo="${{ endpoint: this.uploadUrl, extraInfo: { composedPath: this.computedPath } }}"
|
|
36
|
+
.jwtLocalStorageKey="${this.jwtLocalStorageKey}"
|
|
37
|
+
>
|
|
38
|
+
</etools-upload>
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
customValidation() {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
attachmentsUploaded({ success, error }) {
|
|
45
|
+
if (this.isUploadedAttachment(success)) {
|
|
46
|
+
this.valueChanged({
|
|
47
|
+
url: success.file_link,
|
|
48
|
+
attachment: success.id,
|
|
49
|
+
filename: success.filename,
|
|
50
|
+
file_type: null
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else if (this.isOfflineSavedAttachment(success)) {
|
|
54
|
+
this.valueChanged({
|
|
55
|
+
attachment: success.id,
|
|
56
|
+
filename: success.filename,
|
|
57
|
+
composedPath: [],
|
|
58
|
+
file_type: null
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.warn('Missing fields in parsed attachment');
|
|
63
|
+
this.valueChanged(null);
|
|
64
|
+
}
|
|
65
|
+
if (error && error.length) {
|
|
66
|
+
console.error(error);
|
|
67
|
+
fireEvent(this, 'toast', { text: 'Can not upload attachments. Please try again later' });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
downloadFile(attachment) {
|
|
71
|
+
if (!(attachment === null || attachment === void 0 ? void 0 : attachment.url)) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const link = document.createElement('a');
|
|
75
|
+
link.target = '_blank';
|
|
76
|
+
link.href = attachment.url;
|
|
77
|
+
link.click();
|
|
78
|
+
window.URL.revokeObjectURL(attachment.url);
|
|
79
|
+
}
|
|
80
|
+
isUploadedAttachment(attachment) {
|
|
81
|
+
return (attachment.hasOwnProperty('filename') &&
|
|
82
|
+
attachment.hasOwnProperty('id') &&
|
|
83
|
+
attachment.hasOwnProperty('file_link') &&
|
|
84
|
+
!attachment.hasOwnProperty('unsynced'));
|
|
85
|
+
}
|
|
86
|
+
isOfflineSavedAttachment(attachment) {
|
|
87
|
+
return (attachment.hasOwnProperty('filename') && attachment.hasOwnProperty('id') && attachment.hasOwnProperty('unsynced'));
|
|
88
|
+
}
|
|
89
|
+
static get styles() {
|
|
90
|
+
// language=CSS
|
|
91
|
+
return [...BaseField.styles, SharedStyles, AttachmentsStyles];
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
AttachmentField = __decorate([
|
|
95
|
+
customElement('attachments-field')
|
|
96
|
+
], AttachmentField);
|
|
97
|
+
export { AttachmentField };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TemplateResult } from 'lit-element';
|
|
2
|
+
import { AbstractFieldBaseClass } from '../abstract-field-base.class';
|
|
3
|
+
export declare abstract class BaseField<T> extends AbstractFieldBaseClass<T> {
|
|
4
|
+
set errorMessage(message: string | null);
|
|
5
|
+
get errorMessage(): string | null;
|
|
6
|
+
protected _errorMessage: string | null;
|
|
7
|
+
protected valueChanged(newValue: T): void;
|
|
8
|
+
protected setValue(newValue: T | null): void;
|
|
9
|
+
protected validateField(value: T): void;
|
|
10
|
+
protected abstract controlTemplate(): TemplateResult;
|
|
11
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { property } from 'lit-element';
|
|
8
|
+
import { fireEvent } from '../../lib/utils/fire-custom-event';
|
|
9
|
+
import { AbstractFieldBaseClass } from '../abstract-field-base.class';
|
|
10
|
+
export class BaseField extends AbstractFieldBaseClass {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this._errorMessage = null;
|
|
14
|
+
}
|
|
15
|
+
set errorMessage(message) {
|
|
16
|
+
this._errorMessage = message;
|
|
17
|
+
}
|
|
18
|
+
get errorMessage() {
|
|
19
|
+
return this.isReadonly ? null : this._errorMessage;
|
|
20
|
+
}
|
|
21
|
+
valueChanged(newValue) {
|
|
22
|
+
if (!newValue && this.value === undefined) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!this.isReadonly && newValue !== this.value && this.touched) {
|
|
26
|
+
this.validateField(newValue);
|
|
27
|
+
}
|
|
28
|
+
else if (this.isReadonly || !this.touched) {
|
|
29
|
+
this._errorMessage = null;
|
|
30
|
+
}
|
|
31
|
+
if (newValue !== this.value) {
|
|
32
|
+
this.value = newValue;
|
|
33
|
+
fireEvent(this, 'value-changed', { value: newValue });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
setValue(newValue) {
|
|
37
|
+
this.value = newValue;
|
|
38
|
+
fireEvent(this, 'value-changed', { value: newValue });
|
|
39
|
+
}
|
|
40
|
+
validateField(value) {
|
|
41
|
+
let errorMessage;
|
|
42
|
+
if (this.required && !value && typeof value !== 'number') {
|
|
43
|
+
errorMessage = 'This field is required!';
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
errorMessage = this.metaValidation(value);
|
|
47
|
+
}
|
|
48
|
+
if (this._errorMessage !== errorMessage) {
|
|
49
|
+
fireEvent(this, 'error-changed', { error: errorMessage });
|
|
50
|
+
this._errorMessage = errorMessage;
|
|
51
|
+
this.requestUpdate();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
__decorate([
|
|
56
|
+
property()
|
|
57
|
+
], BaseField.prototype, "_errorMessage", void 0);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CSSResultArray, TemplateResult } from 'lit-element';
|
|
2
|
+
import { BaseField } from './base-field';
|
|
3
|
+
import '@polymer/paper-toggle-button';
|
|
4
|
+
export declare class BooleanField extends BaseField<boolean> {
|
|
5
|
+
protected controlTemplate(): TemplateResult;
|
|
6
|
+
protected customValidation(): string | null;
|
|
7
|
+
static get styles(): CSSResultArray;
|
|
8
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { css, customElement, html } from 'lit-element';
|
|
8
|
+
import { BaseField } from './base-field';
|
|
9
|
+
import '@polymer/paper-toggle-button';
|
|
10
|
+
import { InputStyles } from '../../lib/styles/input-styles';
|
|
11
|
+
let BooleanField = class BooleanField extends BaseField {
|
|
12
|
+
controlTemplate() {
|
|
13
|
+
return html `
|
|
14
|
+
${InputStyles}
|
|
15
|
+
<paper-toggle-button
|
|
16
|
+
class="no-padding-left form-control"
|
|
17
|
+
?checked="${this.value}"
|
|
18
|
+
@iron-change="${(event) => this.valueChanged(event.currentTarget.checked)}"
|
|
19
|
+
?disabled="${this.isReadonly}"
|
|
20
|
+
>
|
|
21
|
+
</paper-toggle-button>
|
|
22
|
+
|
|
23
|
+
<div ?hidden="${!this.errorMessage}" class="error-text">${this.errorMessage}</div>
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
26
|
+
customValidation() {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
static get styles() {
|
|
30
|
+
// language=CSS
|
|
31
|
+
return [
|
|
32
|
+
...BaseField.styles,
|
|
33
|
+
css `
|
|
34
|
+
:host(.wide) paper-textarea {
|
|
35
|
+
padding-left: 0;
|
|
36
|
+
}
|
|
37
|
+
@media (max-width: 380px) {
|
|
38
|
+
.no-padding-left {
|
|
39
|
+
padding-left: 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
BooleanField = __decorate([
|
|
47
|
+
customElement('boolean-field')
|
|
48
|
+
], BooleanField);
|
|
49
|
+
export { BooleanField };
|
|
@@ -2,6 +2,7 @@ import { CSSResultArray, TemplateResult } from 'lit-element';
|
|
|
2
2
|
import { BaseField } from './base-field';
|
|
3
3
|
import '@polymer/paper-input/paper-input';
|
|
4
4
|
export declare class NumberField extends BaseField<number> {
|
|
5
|
+
isInteger: boolean;
|
|
5
6
|
protected controlTemplate(): TemplateResult;
|
|
6
7
|
protected valueChanged(newValue: number): void;
|
|
7
8
|
protected customValidation(value: number): string | null;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { css, customElement, html } from 'lit-element';
|
|
8
|
+
import { BaseField } from './base-field';
|
|
9
|
+
import '@polymer/paper-input/paper-input';
|
|
10
|
+
import { InputStyles } from '../../lib/styles/input-styles';
|
|
11
|
+
let NumberField = class NumberField extends BaseField {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.isInteger = false;
|
|
15
|
+
}
|
|
16
|
+
controlTemplate() {
|
|
17
|
+
return html `
|
|
18
|
+
${InputStyles}
|
|
19
|
+
<paper-input
|
|
20
|
+
class="without-border no-padding-left form-control"
|
|
21
|
+
no-label-float
|
|
22
|
+
placeholder="${this.isReadonly ? '—' : this.placeholder}"
|
|
23
|
+
.value="${this.value}"
|
|
24
|
+
@value-changed="${({ detail }) => this.valueChanged(detail.value)}"
|
|
25
|
+
@focus="${() => (this.touched = true)}"
|
|
26
|
+
placeholder="—"
|
|
27
|
+
?invalid="${this.errorMessage}"
|
|
28
|
+
error-message="${this.errorMessage}"
|
|
29
|
+
?disabled="${this.isReadonly}"
|
|
30
|
+
>
|
|
31
|
+
</paper-input>
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
valueChanged(newValue) {
|
|
35
|
+
const formatted = Number(newValue);
|
|
36
|
+
const isNumber = !isNaN(formatted) && `${newValue}` !== '' && `${newValue}` !== 'null';
|
|
37
|
+
super.valueChanged(isNumber ? formatted : newValue);
|
|
38
|
+
}
|
|
39
|
+
customValidation(value) {
|
|
40
|
+
if (!value) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (isNaN(value)) {
|
|
44
|
+
return 'Must be a number';
|
|
45
|
+
}
|
|
46
|
+
const integerValidation = !this.isInteger || value - Math.floor(value) === 0;
|
|
47
|
+
return integerValidation ? null : 'Must be an integer';
|
|
48
|
+
}
|
|
49
|
+
static get styles() {
|
|
50
|
+
// language=CSS
|
|
51
|
+
return [
|
|
52
|
+
...BaseField.styles,
|
|
53
|
+
css `
|
|
54
|
+
@media (max-width: 380px) {
|
|
55
|
+
.no-padding-left {
|
|
56
|
+
padding-left: 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
`
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
NumberField = __decorate([
|
|
64
|
+
customElement('number-field')
|
|
65
|
+
], NumberField);
|
|
66
|
+
export { NumberField };
|
|
@@ -7,9 +7,11 @@ export declare type FieldOption = {
|
|
|
7
7
|
value: any;
|
|
8
8
|
label: string;
|
|
9
9
|
};
|
|
10
|
-
export declare class ScaleField extends BaseField<string | null> {
|
|
11
|
-
options: FieldOption[];
|
|
10
|
+
export declare class ScaleField extends BaseField<string | number | null> {
|
|
11
|
+
options: (FieldOption | string | number)[];
|
|
12
12
|
protected controlTemplate(): TemplateResult;
|
|
13
|
+
protected getLabel(option: FieldOption | string | number): unknown;
|
|
14
|
+
protected getValue(option: FieldOption | string | number): unknown;
|
|
13
15
|
protected onSelect(item: PaperRadioButtonElement): void;
|
|
14
16
|
protected customValidation(): string | null;
|
|
15
17
|
static get styles(): CSSResultArray;
|
|
@@ -4,13 +4,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { html, property, css } from 'lit-element';
|
|
7
|
+
import { html, property, css, customElement } from 'lit-element';
|
|
8
8
|
import { BaseField } from './base-field';
|
|
9
9
|
import { repeat } from 'lit-html/directives/repeat';
|
|
10
10
|
import '@polymer/paper-radio-group/paper-radio-group';
|
|
11
11
|
import '@polymer/paper-radio-button/paper-radio-button';
|
|
12
|
-
import { InputStyles } from '
|
|
13
|
-
|
|
12
|
+
import { InputStyles } from '../../lib/styles/input-styles';
|
|
13
|
+
let ScaleField = class ScaleField extends BaseField {
|
|
14
14
|
constructor() {
|
|
15
15
|
super(...arguments);
|
|
16
16
|
this.options = [];
|
|
@@ -25,7 +25,9 @@ export class ScaleField extends BaseField {
|
|
|
25
25
|
@iron-select="${({ detail }) => this.onSelect(detail.item)}"
|
|
26
26
|
>
|
|
27
27
|
${repeat(this.options, (option) => html `
|
|
28
|
-
<paper-radio-button class="radio-button" name="${option
|
|
28
|
+
<paper-radio-button class="radio-button" name="${this.getValue(option)}">
|
|
29
|
+
${this.getLabel(option)}
|
|
30
|
+
</paper-radio-button>
|
|
29
31
|
`)}
|
|
30
32
|
</paper-radio-group>
|
|
31
33
|
|
|
@@ -33,10 +35,20 @@ export class ScaleField extends BaseField {
|
|
|
33
35
|
<iron-icon icon="clear"></iron-icon>Clear
|
|
34
36
|
</paper-button>
|
|
35
37
|
</div>
|
|
38
|
+
<div ?hidden="${!this.errorMessage}" class="error-text">${this.errorMessage}</div>
|
|
36
39
|
`;
|
|
37
40
|
}
|
|
41
|
+
getLabel(option) {
|
|
42
|
+
return typeof option === 'object' ? option.label : option;
|
|
43
|
+
}
|
|
44
|
+
getValue(option) {
|
|
45
|
+
return typeof option === 'object' ? option.value : option;
|
|
46
|
+
}
|
|
38
47
|
onSelect(item) {
|
|
39
48
|
const newValue = item.get('name');
|
|
49
|
+
if (newValue !== this.value) {
|
|
50
|
+
this.touched = true;
|
|
51
|
+
}
|
|
40
52
|
this.valueChanged(newValue);
|
|
41
53
|
}
|
|
42
54
|
customValidation() {
|
|
@@ -85,7 +97,11 @@ export class ScaleField extends BaseField {
|
|
|
85
97
|
`
|
|
86
98
|
];
|
|
87
99
|
}
|
|
88
|
-
}
|
|
100
|
+
};
|
|
89
101
|
__decorate([
|
|
90
102
|
property({ type: Array })
|
|
91
103
|
], ScaleField.prototype, "options", void 0);
|
|
104
|
+
ScaleField = __decorate([
|
|
105
|
+
customElement('scale-field')
|
|
106
|
+
], ScaleField);
|
|
107
|
+
export { ScaleField };
|
|
File without changes
|
|
@@ -4,48 +4,51 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
7
|
+
import { css, customElement, html } from 'lit-element';
|
|
8
8
|
import { BaseField } from './base-field';
|
|
9
9
|
import '@polymer/paper-input/paper-textarea';
|
|
10
|
-
import { InputStyles } from '
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
super(...arguments);
|
|
14
|
-
this.label = '';
|
|
15
|
-
this.placeholder = '';
|
|
16
|
-
}
|
|
17
|
-
render() {
|
|
10
|
+
import { InputStyles } from '../../lib/styles/input-styles';
|
|
11
|
+
let TextField = class TextField extends BaseField {
|
|
12
|
+
controlTemplate() {
|
|
18
13
|
return html `
|
|
19
14
|
${InputStyles}
|
|
20
15
|
<paper-textarea
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
label="${this.label}"
|
|
16
|
+
id="textarea"
|
|
17
|
+
class="no-padding-left form-control"
|
|
18
|
+
no-label-float
|
|
25
19
|
placeholder="${this.isReadonly ? '—' : this.placeholder}"
|
|
26
|
-
|
|
20
|
+
.value="${this.value}"
|
|
21
|
+
@value-changed="${({ detail }) => this.valueChanged(detail.value)}"
|
|
22
|
+
@focus="${() => (this.touched = true)}"
|
|
23
|
+
placeholder="—"
|
|
27
24
|
?disabled="${this.isReadonly}"
|
|
28
25
|
?invalid="${this.errorMessage}"
|
|
29
26
|
error-message="${this.errorMessage}"
|
|
30
|
-
@value-changed="${({ detail }) => this.valueChanged(detail.value)}"
|
|
31
27
|
>
|
|
32
28
|
</paper-textarea>
|
|
33
29
|
`;
|
|
34
30
|
}
|
|
35
|
-
controlTemplate() {
|
|
36
|
-
return html ``;
|
|
37
|
-
}
|
|
38
31
|
customValidation() {
|
|
39
32
|
return null;
|
|
40
33
|
}
|
|
41
34
|
static get styles() {
|
|
42
35
|
// language=CSS
|
|
43
|
-
return [
|
|
36
|
+
return [
|
|
37
|
+
...BaseField.styles,
|
|
38
|
+
css `
|
|
39
|
+
:host(.wide) paper-textarea {
|
|
40
|
+
padding-left: 0;
|
|
41
|
+
}
|
|
42
|
+
@media (max-width: 380px) {
|
|
43
|
+
.no-padding-left {
|
|
44
|
+
padding-left: 0;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`
|
|
48
|
+
];
|
|
44
49
|
}
|
|
45
|
-
}
|
|
46
|
-
__decorate([
|
|
47
|
-
|
|
48
|
-
],
|
|
49
|
-
|
|
50
|
-
property()
|
|
51
|
-
], WideField.prototype, "placeholder", void 0);
|
|
50
|
+
};
|
|
51
|
+
TextField = __decorate([
|
|
52
|
+
customElement('text-field')
|
|
53
|
+
], TextField);
|
|
54
|
+
export { TextField };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { LitElement, TemplateResult, CSSResultArray } from 'lit-element';
|
|
2
|
-
import '../form-fields/text-field';
|
|
3
|
-
import '../form-fields/number-field';
|
|
4
|
-
import '../form-fields/scale-field';
|
|
5
|
-
import '../form-fields/wide-field';
|
|
2
|
+
import '../form-fields/single-fields/text-field';
|
|
3
|
+
import '../form-fields/single-fields/number-field';
|
|
4
|
+
import '../form-fields/single-fields/scale-field';
|
|
6
5
|
import '@polymer/paper-input/paper-textarea';
|
|
7
6
|
import { IFormBuilderAbstractGroup } from '../lib/types/form-builder.interfaces';
|
|
8
|
-
import { BlueprintField, BlueprintGroup, BlueprintMetadata } from '../lib/types/form-builder.types';
|
|
7
|
+
import { BlueprintField, BlueprintGroup, BlueprintMetadata, Information } from '../lib/types/form-builder.types';
|
|
9
8
|
import { GenericObject } from '../lib/types/global.types';
|
|
10
9
|
export declare enum FieldTypes {
|
|
11
10
|
FILE_TYPE = "file",
|
|
@@ -47,14 +46,15 @@ export declare class FormAbstractGroup extends LitElement implements IFormBuilde
|
|
|
47
46
|
*/
|
|
48
47
|
set errors(errors: GenericObject | string[] | null);
|
|
49
48
|
render(): TemplateResult;
|
|
50
|
-
renderChild(child: BlueprintGroup | BlueprintField): TemplateResult;
|
|
49
|
+
renderChild(child: BlueprintGroup | BlueprintField | Information): TemplateResult | TemplateResult[];
|
|
51
50
|
renderField(blueprintField: BlueprintField): TemplateResult;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
renderInformation(information: Information): TemplateResult;
|
|
52
|
+
renderGroup(groupStructure: BlueprintGroup): TemplateResult | TemplateResult[];
|
|
53
|
+
getGroupTemplate(groupStructure: BlueprintGroup, index?: number): TemplateResult;
|
|
54
|
+
valueChanged(event: CustomEvent, name: string, index?: number): void;
|
|
55
|
+
errorChanged(event: CustomEvent, name: string, index?: number): void;
|
|
56
|
+
addGroup(name: string): void;
|
|
57
|
+
removeGroup(group: BlueprintGroup, index?: number): void;
|
|
58
58
|
protected getErrorMessage(fieldName: string): string | null;
|
|
59
59
|
static get styles(): CSSResultArray;
|
|
60
60
|
}
|