@unicef-polymer/etools-form-builder 2.1.6 → 2.1.7

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.
Files changed (82) hide show
  1. package/dist/assets/translations.d.ts +6 -6
  2. package/dist/assets/translations.js +67 -67
  3. package/dist/form-attachments-popup/form-attachments-popup.d.ts +86 -86
  4. package/dist/form-attachments-popup/form-attachments-popup.helper.d.ts +8 -8
  5. package/dist/form-attachments-popup/form-attachments-popup.helper.js +14 -14
  6. package/dist/form-attachments-popup/form-attachments-popup.js +207 -207
  7. package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +3 -3
  8. package/dist/form-attachments-popup/form-attachments-popup.tpl.js +11 -11
  9. package/dist/form-attachments-popup/index.d.ts +2 -2
  10. package/dist/form-attachments-popup/index.js +2 -2
  11. package/dist/form-fields/abstract-field-base.class.d.ts +33 -33
  12. package/dist/form-fields/abstract-field-base.class.js +98 -98
  13. package/dist/form-fields/field-renderer-component.d.ts +20 -20
  14. package/dist/form-fields/field-renderer-component.js +108 -108
  15. package/dist/form-fields/index.d.ts +12 -12
  16. package/dist/form-fields/index.js +12 -12
  17. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -17
  18. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +100 -100
  19. package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -20
  20. package/dist/form-fields/repeatable-fields/repeatable-base-field.js +102 -102
  21. package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -10
  22. package/dist/form-fields/repeatable-fields/repeatable-number-field.js +47 -47
  23. package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -15
  24. package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +49 -49
  25. package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -8
  26. package/dist/form-fields/repeatable-fields/repeatable-text-field.js +30 -30
  27. package/dist/form-fields/single-fields/attachment-field.d.ts +16 -16
  28. package/dist/form-fields/single-fields/attachment-field.js +85 -85
  29. package/dist/form-fields/single-fields/base-field.d.ts +11 -11
  30. package/dist/form-fields/single-fields/base-field.js +58 -58
  31. package/dist/form-fields/single-fields/boolean-field.d.ts +8 -8
  32. package/dist/form-fields/single-fields/boolean-field.js +29 -29
  33. package/dist/form-fields/single-fields/number-field.d.ts +10 -10
  34. package/dist/form-fields/single-fields/number-field.js +46 -46
  35. package/dist/form-fields/single-fields/scale-field.d.ts +18 -18
  36. package/dist/form-fields/single-fields/scale-field.js +52 -52
  37. package/dist/form-fields/single-fields/text-field.d.ts +8 -8
  38. package/dist/form-fields/single-fields/text-field.js +29 -29
  39. package/dist/form-groups/form-abstract-group.d.ts +71 -65
  40. package/dist/form-groups/form-abstract-group.js +278 -255
  41. package/dist/form-groups/form-card.d.ts +32 -32
  42. package/dist/form-groups/form-card.js +89 -89
  43. package/dist/form-groups/form-collapsed-card.d.ts +71 -70
  44. package/dist/form-groups/form-collapsed-card.js +230 -225
  45. package/dist/form-groups/index.d.ts +3 -3
  46. package/dist/form-groups/index.js +3 -3
  47. package/dist/index.d.ts +3 -3
  48. package/dist/index.js +3 -3
  49. package/dist/lib/additional-components/confirmation-dialog.d.ts +18 -18
  50. package/dist/lib/additional-components/confirmation-dialog.js +52 -52
  51. package/dist/lib/additional-components/etools-fb-card.d.ts +21 -21
  52. package/dist/lib/additional-components/etools-fb-card.js +99 -99
  53. package/dist/lib/styles/attachments.styles.d.ts +2 -2
  54. package/dist/lib/styles/attachments.styles.js +3 -3
  55. package/dist/lib/styles/card-styles.d.ts +2 -2
  56. package/dist/lib/styles/card-styles.js +3 -3
  57. package/dist/lib/styles/dialog.styles.d.ts +2 -2
  58. package/dist/lib/styles/dialog.styles.js +3 -3
  59. package/dist/lib/styles/elevation-styles.d.ts +9 -9
  60. package/dist/lib/styles/elevation-styles.js +10 -10
  61. package/dist/lib/styles/flex-layout-classes.d.ts +2 -2
  62. package/dist/lib/styles/flex-layout-classes.js +3 -3
  63. package/dist/lib/styles/form-builder-card.styles.d.ts +2 -2
  64. package/dist/lib/styles/form-builder-card.styles.js +3 -3
  65. package/dist/lib/styles/input-styles.d.ts +2 -2
  66. package/dist/lib/styles/input-styles.js +3 -3
  67. package/dist/lib/styles/page-layout-styles.d.ts +2 -2
  68. package/dist/lib/styles/page-layout-styles.js +3 -3
  69. package/dist/lib/styles/shared-styles.d.ts +2 -2
  70. package/dist/lib/styles/shared-styles.js +3 -3
  71. package/dist/lib/types/form-builder.interfaces.d.ts +83 -83
  72. package/dist/lib/types/form-builder.types.d.ts +59 -59
  73. package/dist/lib/types/global.types.d.ts +4 -4
  74. package/dist/lib/utils/dialog.d.ts +10 -10
  75. package/dist/lib/utils/dialog.js +21 -21
  76. package/dist/lib/utils/fire-custom-event.d.ts +1 -1
  77. package/dist/lib/utils/fire-custom-event.js +7 -7
  78. package/dist/lib/utils/translate.d.ts +1 -1
  79. package/dist/lib/utils/translate.js +9 -9
  80. package/dist/lib/utils/validations.helper.d.ts +26 -26
  81. package/dist/lib/utils/validations.helper.js +42 -42
  82. package/package.json +1 -1
@@ -1,118 +1,136 @@
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 { LitElement, property, html, css, customElement } from 'lit-element';
8
- import '../form-fields/single-fields/text-field';
9
- import '../form-fields/single-fields/number-field';
10
- import '../form-fields/single-fields/scale-field';
11
- import '@polymer/paper-input/paper-textarea';
12
- import { SharedStyles } from '../lib/styles/shared-styles';
13
- import { pageLayoutStyles } from '../lib/styles/page-layout-styles';
14
- import { elevationStyles } from '../lib/styles/elevation-styles';
15
- import { CardStyles } from '../lib/styles/card-styles';
16
- import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
17
- import { fireEvent } from '../lib/utils/fire-custom-event';
18
- import { clone } from 'ramda';
19
- import { live } from 'lit-html/directives/live';
20
- import { openDialog } from '../lib/utils/dialog';
21
- import { FormBuilderCardStyles } from '../lib/styles/form-builder-card.styles';
22
- import { getTranslation } from '../lib/utils/translate';
23
- export var FieldTypes;
24
- (function (FieldTypes) {
25
- FieldTypes["FILE_TYPE"] = "file";
26
- FieldTypes["TEXT_TYPE"] = "text";
27
- FieldTypes["NUMBER_TYPE"] = "number";
28
- FieldTypes["BOOL_TYPE"] = "bool";
29
- FieldTypes["SCALE_TYPE"] = "likert_scale";
30
- FieldTypes["NUMBER_INTEGER_TYPE"] = "number-integer";
31
- FieldTypes["NUMBER_FLOAT_TYPE"] = "number-float";
32
- })(FieldTypes || (FieldTypes = {}));
33
- export var StructureTypes;
34
- (function (StructureTypes) {
35
- StructureTypes["WIDE"] = "wide";
36
- StructureTypes["ADDITIONAL"] = "additional";
37
- StructureTypes["CARD"] = "card";
38
- StructureTypes["ABSTRACT"] = "abstract";
39
- StructureTypes["COLLAPSED"] = "collapse";
40
- StructureTypes["ATTACHMENTS_BUTTON"] = "floating_attachments";
41
- })(StructureTypes || (StructureTypes = {}));
42
- let FormAbstractGroup = class FormAbstractGroup extends LitElement {
43
- constructor() {
44
- super();
45
- this.parentGroupName = '';
46
- this.readonly = false;
47
- this._errors = {};
48
- this._value = {};
49
- this.computedPath = [];
50
- if (!this.language) {
51
- this.language = window.localStorage.defaultLanguage || 'en';
52
- }
53
- this.handleLanguageChange = this.handleLanguageChange.bind(this);
54
- }
55
- /**
56
- * Make value property immutable
57
- * @param value
58
- */
59
- set value(value) {
60
- this._value = this.groupStructure.name === 'root' ? clone(value) : value;
61
- }
62
- get value() {
63
- return this._value;
64
- }
65
- /**
66
- * Setter for handling error.
67
- * Normally we wouldn't have errors as string or string[] for FormGroups.
68
- * In cases they appear - show toast with error text and reset it.
69
- * Otherwise it will be impossible to clear that error from field elements
70
- * @param errors
71
- */
72
- set errors(errors) {
73
- if (Array.isArray(errors)) {
74
- fireEvent(this, 'toast', { text: errors[0] });
75
- fireEvent(this, 'error-changed', { error: null });
76
- }
77
- else if (errors) {
78
- this._errors = errors;
79
- }
80
- }
81
- connectedCallback() {
82
- super.connectedCallback();
83
- document.addEventListener('language-changed', this.handleLanguageChange.bind(this));
84
- }
85
- disconnectedCallback() {
86
- super.disconnectedCallback();
87
- document.removeEventListener('language-changed', this.handleLanguageChange.bind(this));
88
- }
89
- handleLanguageChange(e) {
90
- this.language = e.detail.language;
91
- }
92
- render() {
93
- if (!this.groupStructure || !this.metadata) {
94
- return html ``;
95
- }
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 { LitElement, property, html, css, customElement } from 'lit-element';
8
+ import '../form-fields/single-fields/text-field';
9
+ import '../form-fields/single-fields/number-field';
10
+ import '../form-fields/single-fields/scale-field';
11
+ import '@polymer/paper-input/paper-textarea';
12
+ import { SharedStyles } from '../lib/styles/shared-styles';
13
+ import { pageLayoutStyles } from '../lib/styles/page-layout-styles';
14
+ import { elevationStyles } from '../lib/styles/elevation-styles';
15
+ import { CardStyles } from '../lib/styles/card-styles';
16
+ import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
17
+ import { fireEvent } from '../lib/utils/fire-custom-event';
18
+ import { clone } from 'ramda';
19
+ import { live } from 'lit-html/directives/live';
20
+ import { openDialog } from '../lib/utils/dialog';
21
+ import { FormBuilderCardStyles } from '../lib/styles/form-builder-card.styles';
22
+ import { getTranslation } from '../lib/utils/translate';
23
+ export var FieldTypes;
24
+ (function (FieldTypes) {
25
+ FieldTypes["FILE_TYPE"] = "file";
26
+ FieldTypes["TEXT_TYPE"] = "text";
27
+ FieldTypes["NUMBER_TYPE"] = "number";
28
+ FieldTypes["BOOL_TYPE"] = "bool";
29
+ FieldTypes["SCALE_TYPE"] = "likert_scale";
30
+ FieldTypes["NUMBER_INTEGER_TYPE"] = "number-integer";
31
+ FieldTypes["NUMBER_FLOAT_TYPE"] = "number-float";
32
+ })(FieldTypes || (FieldTypes = {}));
33
+ export var StructureTypes;
34
+ (function (StructureTypes) {
35
+ StructureTypes["WIDE"] = "wide";
36
+ StructureTypes["ADDITIONAL"] = "additional";
37
+ StructureTypes["CARD"] = "card";
38
+ StructureTypes["ABSTRACT"] = "abstract";
39
+ StructureTypes["COLLAPSED"] = "collapse";
40
+ StructureTypes["ATTACHMENTS_BUTTON"] = "floating_attachments";
41
+ })(StructureTypes || (StructureTypes = {}));
42
+ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
43
+ constructor() {
44
+ super();
45
+ this.parentGroupName = '';
46
+ this.collapsed = false;
47
+ this.readonly = false;
48
+ this._errors = {};
49
+ this._value = {};
50
+ this.computedPath = [];
51
+ if (!this.language) {
52
+ this.language = window.localStorage.defaultLanguage || 'en';
53
+ }
54
+ this.handleLanguageChange = this.handleLanguageChange.bind(this);
55
+ }
56
+ /**
57
+ * Make value property immutable
58
+ * @param value
59
+ */
60
+ set value(value) {
61
+ this._value = this.groupStructure.name === 'root' ? clone(value) : value;
62
+ if (this.groupStructure.name === 'root') {
63
+ const res = this.countCollapsePanels(this.groupStructure, { count: 0 });
64
+ // if more than 2 collapse panels, show them collapsed by default
65
+ this.collapsed = res.count > 2;
66
+ }
67
+ }
68
+ get value() {
69
+ return this._value;
70
+ }
71
+ /**
72
+ * Setter for handling error.
73
+ * Normally we wouldn't have errors as string or string[] for FormGroups.
74
+ * In cases they appear - show toast with error text and reset it.
75
+ * Otherwise it will be impossible to clear that error from field elements
76
+ * @param errors
77
+ */
78
+ set errors(errors) {
79
+ if (Array.isArray(errors)) {
80
+ fireEvent(this, 'toast', { text: errors[0] });
81
+ fireEvent(this, 'error-changed', { error: null });
82
+ }
83
+ else if (errors) {
84
+ this._errors = errors;
85
+ }
86
+ }
87
+ connectedCallback() {
88
+ super.connectedCallback();
89
+ document.addEventListener('language-changed', this.handleLanguageChange.bind(this));
90
+ }
91
+ disconnectedCallback() {
92
+ super.disconnectedCallback();
93
+ document.removeEventListener('language-changed', this.handleLanguageChange.bind(this));
94
+ }
95
+ countCollapsePanels(groupStructure, res) {
96
+ if (groupStructure.type === 'group' && groupStructure.children) {
97
+ groupStructure.children.forEach((child) => this.countCollapsePanels(child, res));
98
+ }
99
+ const isAbstract = groupStructure.styling.includes(StructureTypes.ABSTRACT);
100
+ const isCard = groupStructure.styling.includes(StructureTypes.CARD);
101
+ const isCollapsed = groupStructure.styling.includes(StructureTypes.COLLAPSED);
102
+ if (!isAbstract && isCard && isCollapsed) {
103
+ res.count++;
104
+ }
105
+ return res;
106
+ }
107
+ handleLanguageChange(e) {
108
+ this.language = e.detail.language;
109
+ }
110
+ render() {
111
+ if (!this.groupStructure || !this.metadata) {
112
+ return html ``;
113
+ }
96
114
  return html `
97
115
  ${this.groupStructure.children.map((child) => this.renderChild(child))}
98
- `;
99
- }
100
- renderChild(child) {
101
- const type = child.type;
102
- switch (child.type) {
103
- case 'field':
104
- return this.renderField(child);
105
- case 'group':
106
- return this.renderGroup(child);
107
- case 'information':
108
- return this.renderInformation(child);
109
- default:
110
- console.warn(`FormBuilderGroup: Unknown group type ${type}. Please, specify rendering method`);
111
- return html ``;
112
- }
113
- }
114
- renderField(blueprintField) {
115
- var _a;
116
+ `;
117
+ }
118
+ renderChild(child) {
119
+ const type = child.type;
120
+ switch (child.type) {
121
+ case 'field':
122
+ return this.renderField(child);
123
+ case 'group':
124
+ return this.renderGroup(child);
125
+ case 'information':
126
+ return this.renderInformation(child);
127
+ default:
128
+ console.warn(`FormBuilderGroup: Unknown group type ${type}. Please, specify rendering method`);
129
+ return html ``;
130
+ }
131
+ }
132
+ renderField(blueprintField) {
133
+ var _a;
116
134
  return html `
117
135
  <field-renderer
118
136
  .field="${blueprintField}"
@@ -125,60 +143,62 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
125
143
  @value-changed="${(event) => this.valueChanged(event, blueprintField.name)}"
126
144
  @error-changed="${(event) => this.errorChanged(event, blueprintField.name)}"
127
145
  ></field-renderer>
128
- `;
129
- }
130
- renderInformation(information) {
131
- return html `<section class="elevation page-content" elevation="1">${information.text}</section>`;
132
- }
133
- renderGroup(groupStructure) {
134
- if (!groupStructure.repeatable) {
135
- return this.getGroupTemplate(groupStructure);
136
- }
137
- const value = (this.value && this.value[groupStructure.name]) || [{}];
146
+ `;
147
+ }
148
+ renderInformation(information) {
149
+ return html `<section class="elevation page-content" elevation="1">${information.text}</section>`;
150
+ }
151
+ renderGroup(groupStructure) {
152
+ if (!groupStructure.repeatable) {
153
+ return this.getGroupTemplate(groupStructure);
154
+ }
155
+ const value = (this.value && this.value[groupStructure.name]) || [{}];
138
156
  return html `
139
157
  ${value.map((_, index) => this.getGroupTemplate(groupStructure, index))}
140
158
  <paper-button class="add-group save-button" @click="${() => this.addGroup(groupStructure.name)}">
141
159
  ${getTranslation(this.language, 'ADD')}
142
- ${!groupStructure.title || groupStructure.title.length > 15
143
- ? getTranslation(this.language, 'GROUP')
160
+ ${!groupStructure.title || groupStructure.title.length > 15
161
+ ? getTranslation(this.language, 'GROUP')
144
162
  : groupStructure.title}
145
163
  </paper-button>
146
- `;
147
- }
148
- getGroupTemplate(groupStructure, index) {
149
- const isAbstract = groupStructure.styling.includes(StructureTypes.ABSTRACT);
150
- const isCard = groupStructure.styling.includes(StructureTypes.CARD);
151
- const isCollapsed = groupStructure.styling.includes(StructureTypes.COLLAPSED);
152
- let value = this.value && this.value[groupStructure.name];
153
- if (typeof index === 'number') {
154
- value = value && value[index];
155
- }
156
- let errors = this._errors[groupStructure.name];
157
- if (typeof index === 'number') {
158
- errors = errors && errors[index];
159
- }
160
- if (isAbstract) {
164
+ `;
165
+ }
166
+ getGroupTemplate(groupStructure, index) {
167
+ const isAbstract = groupStructure.styling.includes(StructureTypes.ABSTRACT);
168
+ const isCard = groupStructure.styling.includes(StructureTypes.CARD);
169
+ const isCollapsed = groupStructure.styling.includes(StructureTypes.COLLAPSED);
170
+ let value = this.value && this.value[groupStructure.name];
171
+ if (typeof index === 'number') {
172
+ value = value && value[index];
173
+ }
174
+ let errors = this._errors[groupStructure.name];
175
+ if (typeof index === 'number') {
176
+ errors = errors && errors[index];
177
+ }
178
+ if (isAbstract) {
161
179
  return html `
162
180
  <form-abstract-group
163
181
  .groupStructure="${groupStructure}"
164
182
  .value="${value}"
165
183
  .metadata="${this.metadata}"
166
184
  .parentGroupName="${this.groupStructure.name}"
185
+ .collapsed="${this.collapsed}"
167
186
  .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
168
187
  .readonly="${this.readonly}"
169
188
  .errors="${errors || null}"
170
189
  @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
171
190
  @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
172
191
  ></form-abstract-group>
173
- `;
174
- }
175
- else if (isCard && isCollapsed) {
192
+ `;
193
+ }
194
+ else if (isCard && isCollapsed) {
176
195
  return html `
177
196
  <form-collapsed-card
178
197
  .groupStructure="${groupStructure}"
179
198
  .value="${value}"
180
199
  .metadata="${this.metadata}"
181
200
  .parentGroupName="${this.groupStructure.name}"
201
+ .collapsed="${this.collapsed}"
182
202
  .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
183
203
  .readonly="${this.readonly}"
184
204
  .errors="${errors || null}"
@@ -186,9 +206,9 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
186
206
  @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
187
207
  @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
188
208
  ></form-collapsed-card>
189
- `;
190
- }
191
- else if (isCard) {
209
+ `;
210
+ }
211
+ else if (isCard) {
192
212
  return html `
193
213
  <form-card
194
214
  .groupStructure="${groupStructure}"
@@ -202,86 +222,86 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
202
222
  @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
203
223
  @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
204
224
  ></form-card>
205
- `;
206
- }
207
- else {
208
- console.warn(`FormBuilderGroup: Unknown group type: ${groupStructure.styling}`);
209
- return html ``;
210
- }
211
- }
212
- valueChanged(event, name, index) {
213
- if (!this.value) {
214
- this.value = {};
215
- }
216
- if (typeof index === 'number') {
217
- const value = this.value[name] || [];
218
- value[index] = event.detail.value;
219
- this.value[name] = value;
220
- }
221
- else {
222
- this.value[name] = event.detail.value;
223
- }
224
- if (event.stopPropagation) {
225
- event.stopPropagation();
226
- }
227
- fireEvent(this, 'value-changed', { value: this.value });
228
- this.requestUpdate();
229
- }
230
- errorChanged(event, name, index) {
231
- const errorMessage = event.detail.error;
232
- if (typeof index === 'number') {
233
- const errors = this._errors[name] || (this.value && new Array(this.value[name].length).fill(null)) || [];
234
- errors.splice(index, 1, errorMessage);
235
- const hasErrors = errors.some((error) => error !== null);
236
- this._errors[name] = hasErrors ? errors : null;
237
- }
238
- else if (errorMessage) {
239
- this._errors[name] = errorMessage;
240
- }
241
- else {
242
- delete this._errors[name];
243
- }
244
- event.stopPropagation();
245
- const errors = Object.keys(this._errors).length ? this._errors : null;
246
- fireEvent(this, 'error-changed', { error: errors });
247
- }
248
- addGroup(name) {
249
- const value = this.value[name] || [];
250
- value.push({});
251
- this.valueChanged({ detail: { value } }, name);
252
- }
253
- removeGroup(group, index) {
254
- if (typeof index !== 'number') {
255
- return;
256
- }
257
- const value = (this.value && this.value[group.name]) || [];
258
- if (group.required && value.length < 2) {
259
- openDialog({
260
- dialog: 'confirmation-popup',
261
- dialogData: {
262
- text: getTranslation(this.language, 'GROUP_REQUIRED'),
263
- hideConfirmBtn: true,
264
- dialogTitle: ''
265
- }
266
- });
267
- return;
268
- }
269
- value.splice(index, 1);
270
- this.valueChanged({ detail: { value } }, group.name);
271
- }
272
- getErrorMessage(fieldName) {
273
- const error = this._errors && this._errors[fieldName];
274
- return Array.isArray(error) ? error[0] : error || null;
275
- }
276
- static get styles() {
277
- // language=CSS
278
- return [
279
- SharedStyles,
280
- pageLayoutStyles,
281
- elevationStyles,
282
- CardStyles,
283
- FlexLayoutClasses,
284
- FormBuilderCardStyles,
225
+ `;
226
+ }
227
+ else {
228
+ console.warn(`FormBuilderGroup: Unknown group type: ${groupStructure.styling}`);
229
+ return html ``;
230
+ }
231
+ }
232
+ valueChanged(event, name, index) {
233
+ if (!this.value) {
234
+ this.value = {};
235
+ }
236
+ if (typeof index === 'number') {
237
+ const value = this.value[name] || [];
238
+ value[index] = event.detail.value;
239
+ this.value[name] = value;
240
+ }
241
+ else {
242
+ this.value[name] = event.detail.value;
243
+ }
244
+ if (event.stopPropagation) {
245
+ event.stopPropagation();
246
+ }
247
+ fireEvent(this, 'value-changed', { value: this.value });
248
+ this.requestUpdate();
249
+ }
250
+ errorChanged(event, name, index) {
251
+ const errorMessage = event.detail.error;
252
+ if (typeof index === 'number') {
253
+ const errors = this._errors[name] || (this.value && new Array(this.value[name].length).fill(null)) || [];
254
+ errors.splice(index, 1, errorMessage);
255
+ const hasErrors = errors.some((error) => error !== null);
256
+ this._errors[name] = hasErrors ? errors : null;
257
+ }
258
+ else if (errorMessage) {
259
+ this._errors[name] = errorMessage;
260
+ }
261
+ else {
262
+ delete this._errors[name];
263
+ }
264
+ event.stopPropagation();
265
+ const errors = Object.keys(this._errors).length ? this._errors : null;
266
+ fireEvent(this, 'error-changed', { error: errors });
267
+ }
268
+ addGroup(name) {
269
+ const value = this.value[name] || [];
270
+ value.push({});
271
+ this.valueChanged({ detail: { value } }, name);
272
+ }
273
+ removeGroup(group, index) {
274
+ if (typeof index !== 'number') {
275
+ return;
276
+ }
277
+ const value = (this.value && this.value[group.name]) || [];
278
+ if (group.required && value.length < 2) {
279
+ openDialog({
280
+ dialog: 'confirmation-popup',
281
+ dialogData: {
282
+ text: getTranslation(this.language, 'GROUP_REQUIRED'),
283
+ hideConfirmBtn: true,
284
+ dialogTitle: ''
285
+ }
286
+ });
287
+ return;
288
+ }
289
+ value.splice(index, 1);
290
+ this.valueChanged({ detail: { value } }, group.name);
291
+ }
292
+ getErrorMessage(fieldName) {
293
+ const error = this._errors && this._errors[fieldName];
294
+ return Array.isArray(error) ? error[0] : error || null;
295
+ }
296
+ static get styles() {
297
+ // language=CSS
298
+ return [
299
+ SharedStyles,
300
+ pageLayoutStyles,
301
+ elevationStyles,
302
+ CardStyles,
303
+ FlexLayoutClasses,
304
+ FormBuilderCardStyles,
285
305
  css `
286
306
  :host {
287
307
  display: flex;
@@ -344,32 +364,35 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
344
364
  cursor: pointer;
345
365
  color: var(--primary-text-color);
346
366
  }
347
- `
348
- ];
349
- }
350
- };
351
- __decorate([
352
- property({ type: Object })
353
- ], FormAbstractGroup.prototype, "groupStructure", void 0);
354
- __decorate([
355
- property({ type: Object })
356
- ], FormAbstractGroup.prototype, "metadata", void 0);
357
- __decorate([
358
- property({ type: String })
359
- ], FormAbstractGroup.prototype, "parentGroupName", void 0);
360
- __decorate([
361
- property()
362
- ], FormAbstractGroup.prototype, "language", void 0);
363
- __decorate([
364
- property({ type: Boolean, attribute: 'readonly' })
365
- ], FormAbstractGroup.prototype, "readonly", void 0);
366
- __decorate([
367
- property()
368
- ], FormAbstractGroup.prototype, "_errors", void 0);
369
- __decorate([
370
- property()
371
- ], FormAbstractGroup.prototype, "_value", void 0);
372
- FormAbstractGroup = __decorate([
373
- customElement('form-abstract-group')
374
- ], FormAbstractGroup);
375
- export { FormAbstractGroup };
367
+ `
368
+ ];
369
+ }
370
+ };
371
+ __decorate([
372
+ property({ type: Object })
373
+ ], FormAbstractGroup.prototype, "groupStructure", void 0);
374
+ __decorate([
375
+ property({ type: Object })
376
+ ], FormAbstractGroup.prototype, "metadata", void 0);
377
+ __decorate([
378
+ property({ type: String })
379
+ ], FormAbstractGroup.prototype, "parentGroupName", void 0);
380
+ __decorate([
381
+ property({ type: Boolean })
382
+ ], FormAbstractGroup.prototype, "collapsed", void 0);
383
+ __decorate([
384
+ property()
385
+ ], FormAbstractGroup.prototype, "language", void 0);
386
+ __decorate([
387
+ property({ type: Boolean, attribute: 'readonly' })
388
+ ], FormAbstractGroup.prototype, "readonly", void 0);
389
+ __decorate([
390
+ property()
391
+ ], FormAbstractGroup.prototype, "_errors", void 0);
392
+ __decorate([
393
+ property()
394
+ ], FormAbstractGroup.prototype, "_value", void 0);
395
+ FormAbstractGroup = __decorate([
396
+ customElement('form-abstract-group')
397
+ ], FormAbstractGroup);
398
+ export { FormAbstractGroup };
@@ -1,32 +1,32 @@
1
- import { TemplateResult } from 'lit-element';
2
- import { IFormBuilderCard } from '../lib/types/form-builder.interfaces';
3
- import { FormAbstractGroup } from './form-abstract-group';
4
- import { GenericObject } from '../lib/types/global.types';
5
- import '@polymer/iron-collapse';
6
- export declare class FormCard extends FormAbstractGroup implements IFormBuilderCard {
7
- protected _value: GenericObject;
8
- /**
9
- * Show save button only if value was changed by user
10
- */
11
- private showSaveButton;
12
- /**
13
- * Overrides value property. Saves originalValue.
14
- * We need to update inner _value only if it wasn't change
15
- * @param value
16
- */
17
- set value(value: GenericObject);
18
- get value(): GenericObject;
19
- protected originalValue: GenericObject;
20
- /**
21
- * Extends parent render method,
22
- * adds card-container html wrapper and dynamic save button
23
- */
24
- render(): TemplateResult;
25
- /**
26
- * Updates value property, stops event propagation.
27
- * We need to fire value-changed event only after save button click
28
- */
29
- valueChanged(event: CustomEvent, name: string): void;
30
- saveChanges(): void;
31
- confirmRemove(groupName: string): void;
32
- }
1
+ import { TemplateResult } from 'lit-element';
2
+ import { IFormBuilderCard } from '../lib/types/form-builder.interfaces';
3
+ import { FormAbstractGroup } from './form-abstract-group';
4
+ import { GenericObject } from '../lib/types/global.types';
5
+ import '@polymer/iron-collapse';
6
+ export declare class FormCard extends FormAbstractGroup implements IFormBuilderCard {
7
+ protected _value: GenericObject;
8
+ /**
9
+ * Show save button only if value was changed by user
10
+ */
11
+ private showSaveButton;
12
+ /**
13
+ * Overrides value property. Saves originalValue.
14
+ * We need to update inner _value only if it wasn't change
15
+ * @param value
16
+ */
17
+ set value(value: GenericObject);
18
+ get value(): GenericObject;
19
+ protected originalValue: GenericObject;
20
+ /**
21
+ * Extends parent render method,
22
+ * adds card-container html wrapper and dynamic save button
23
+ */
24
+ render(): TemplateResult;
25
+ /**
26
+ * Updates value property, stops event propagation.
27
+ * We need to fire value-changed event only after save button click
28
+ */
29
+ valueChanged(event: CustomEvent, name: string): void;
30
+ saveChanges(): void;
31
+ confirmRemove(groupName: string): void;
32
+ }