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

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 +117 -98
  13. package/dist/form-fields/field-renderer-component.d.ts +20 -20
  14. package/dist/form-fields/field-renderer-component.js +114 -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 +65 -65
  40. package/dist/form-groups/form-abstract-group.js +255 -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 +70 -70
  44. package/dist/form-groups/form-collapsed-card.js +225 -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 +4 -4
@@ -1,118 +1,118 @@
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.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
+ }
96
96
  return html `
97
97
  ${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;
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
116
  return html `
117
117
  <field-renderer
118
118
  .field="${blueprintField}"
@@ -125,39 +125,39 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
125
125
  @value-changed="${(event) => this.valueChanged(event, blueprintField.name)}"
126
126
  @error-changed="${(event) => this.errorChanged(event, blueprintField.name)}"
127
127
  ></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]) || [{}];
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]) || [{}];
138
138
  return html `
139
139
  ${value.map((_, index) => this.getGroupTemplate(groupStructure, index))}
140
140
  <paper-button class="add-group save-button" @click="${() => this.addGroup(groupStructure.name)}">
141
141
  ${getTranslation(this.language, 'ADD')}
142
- ${!groupStructure.title || groupStructure.title.length > 15
143
- ? getTranslation(this.language, 'GROUP')
142
+ ${!groupStructure.title || groupStructure.title.length > 15
143
+ ? getTranslation(this.language, 'GROUP')
144
144
  : groupStructure.title}
145
145
  </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) {
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) {
161
161
  return html `
162
162
  <form-abstract-group
163
163
  .groupStructure="${groupStructure}"
@@ -170,9 +170,9 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
170
170
  @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
171
171
  @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
172
172
  ></form-abstract-group>
173
- `;
174
- }
175
- else if (isCard && isCollapsed) {
173
+ `;
174
+ }
175
+ else if (isCard && isCollapsed) {
176
176
  return html `
177
177
  <form-collapsed-card
178
178
  .groupStructure="${groupStructure}"
@@ -186,9 +186,9 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
186
186
  @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
187
187
  @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
188
188
  ></form-collapsed-card>
189
- `;
190
- }
191
- else if (isCard) {
189
+ `;
190
+ }
191
+ else if (isCard) {
192
192
  return html `
193
193
  <form-card
194
194
  .groupStructure="${groupStructure}"
@@ -202,86 +202,86 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
202
202
  @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
203
203
  @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
204
204
  ></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,
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,
285
285
  css `
286
286
  :host {
287
287
  display: flex;
@@ -344,32 +344,32 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
344
344
  cursor: pointer;
345
345
  color: var(--primary-text-color);
346
346
  }
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 };
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 };
@@ -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
+ }