@formio/js 5.2.0-rc.9 → 5.2.1-dev.6186.ffe4f6c

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 (81) hide show
  1. package/Changelog.md +6945 -0
  2. package/dist/formio.builder.css +15 -17
  3. package/dist/formio.builder.min.css +1 -1
  4. package/dist/formio.embed.js +1 -1
  5. package/dist/formio.embed.min.js +1 -1
  6. package/dist/formio.embed.min.js.LICENSE.txt +1 -1
  7. package/dist/formio.form.css +15 -17
  8. package/dist/formio.form.js +44 -55
  9. package/dist/formio.form.min.css +1 -1
  10. package/dist/formio.form.min.js +1 -1
  11. package/dist/formio.form.min.js.LICENSE.txt +3 -3
  12. package/dist/formio.full.css +15 -17
  13. package/dist/formio.full.js +46 -57
  14. package/dist/formio.full.min.css +1 -1
  15. package/dist/formio.full.min.js +1 -1
  16. package/dist/formio.full.min.js.LICENSE.txt +3 -3
  17. package/dist/formio.js +19 -30
  18. package/dist/formio.min.js +1 -1
  19. package/dist/formio.min.js.LICENSE.txt +1 -1
  20. package/dist/formio.utils.js +18 -29
  21. package/dist/formio.utils.min.js +1 -1
  22. package/dist/formio.utils.min.js.LICENSE.txt +1 -1
  23. package/lib/cjs/Embed.js +1 -1
  24. package/lib/cjs/Formio.js +1 -1
  25. package/lib/cjs/PDFBuilder.js +8 -6
  26. package/lib/cjs/Webform.js +3 -2
  27. package/lib/cjs/WebformBuilder.js +18 -11
  28. package/lib/cjs/Wizard.d.ts +1 -2
  29. package/lib/cjs/Wizard.js +17 -23
  30. package/lib/cjs/components/Components.js +7 -1
  31. package/lib/cjs/components/_classes/component/Component.d.ts +23 -2
  32. package/lib/cjs/components/_classes/component/Component.js +61 -35
  33. package/lib/cjs/components/_classes/nested/NestedComponent.d.ts +1 -0
  34. package/lib/cjs/components/_classes/nested/NestedComponent.js +11 -3
  35. package/lib/cjs/components/file/File.d.ts +1 -1
  36. package/lib/cjs/components/file/File.js +6 -1
  37. package/lib/cjs/components/form/Form.d.ts +0 -2
  38. package/lib/cjs/components/form/Form.js +12 -20
  39. package/lib/cjs/components/select/Select.d.ts +1 -1
  40. package/lib/cjs/components/select/Select.js +17 -26
  41. package/lib/cjs/components/tags/Tags.d.ts +1 -1
  42. package/lib/cjs/components/tags/Tags.js +2 -2
  43. package/lib/cjs/formio.form.js +1 -0
  44. package/lib/cjs/utils/ChoicesWrapper.d.ts +4 -25
  45. package/lib/cjs/utils/ChoicesWrapper.js +47 -124
  46. package/lib/cjs/utils/formUtils.d.ts +3 -3
  47. package/lib/cjs/utils/index.d.ts +5 -5
  48. package/lib/cjs/utils/utils.d.ts +4 -4
  49. package/lib/cjs/utils/utils.js +2 -2
  50. package/lib/cjs/widgets/CalendarWidget.d.ts +1 -1
  51. package/lib/cjs/widgets/CalendarWidget.js +1 -1
  52. package/lib/mjs/Embed.js +1 -1
  53. package/lib/mjs/Formio.js +1 -1
  54. package/lib/mjs/PDFBuilder.js +8 -6
  55. package/lib/mjs/Webform.js +2 -2
  56. package/lib/mjs/WebformBuilder.js +19 -12
  57. package/lib/mjs/Wizard.d.ts +1 -2
  58. package/lib/mjs/Wizard.js +16 -22
  59. package/lib/mjs/components/Components.js +7 -1
  60. package/lib/mjs/components/_classes/component/Component.d.ts +23 -2
  61. package/lib/mjs/components/_classes/component/Component.js +61 -35
  62. package/lib/mjs/components/_classes/nested/NestedComponent.d.ts +1 -0
  63. package/lib/mjs/components/_classes/nested/NestedComponent.js +11 -3
  64. package/lib/mjs/components/file/File.d.ts +1 -1
  65. package/lib/mjs/components/file/File.js +6 -1
  66. package/lib/mjs/components/form/Form.d.ts +0 -2
  67. package/lib/mjs/components/form/Form.js +12 -20
  68. package/lib/mjs/components/select/Select.d.ts +1 -1
  69. package/lib/mjs/components/select/Select.js +17 -25
  70. package/lib/mjs/components/tags/Tags.d.ts +1 -1
  71. package/lib/mjs/components/tags/Tags.js +2 -2
  72. package/lib/mjs/formio.form.js +1 -0
  73. package/lib/mjs/utils/ChoicesWrapper.d.ts +4 -25
  74. package/lib/mjs/utils/ChoicesWrapper.js +26 -119
  75. package/lib/mjs/utils/formUtils.d.ts +3 -3
  76. package/lib/mjs/utils/index.d.ts +5 -5
  77. package/lib/mjs/utils/utils.d.ts +4 -4
  78. package/lib/mjs/utils/utils.js +2 -2
  79. package/lib/mjs/widgets/CalendarWidget.d.ts +1 -1
  80. package/lib/mjs/widgets/CalendarWidget.js +1 -1
  81. package/package.json +5 -5
@@ -6,7 +6,6 @@ declare class Wizard extends Webform {
6
6
  originalComponents: any[];
7
7
  page: number;
8
8
  currentPanel: any;
9
- currentPanels: any[] | null;
10
9
  currentNextPage: number;
11
10
  _seenPages: number[];
12
11
  subWizards: any[];
@@ -17,7 +16,7 @@ declare class Wizard extends Webform {
17
16
  originalOptions: any;
18
17
  isLastPage(): any;
19
18
  getPages(args?: {}): any[];
20
- get hasExtraPages(): boolean;
19
+ get hasSubWizards(): boolean;
21
20
  get localData(): any;
22
21
  get wizardKey(): string;
23
22
  set wizard(form: object);
package/lib/mjs/Wizard.js CHANGED
@@ -29,7 +29,6 @@ export default class Wizard extends Webform {
29
29
  this.originalComponents = [];
30
30
  this.page = 0;
31
31
  this.currentPanel = null;
32
- this.currentPanels = null;
33
32
  this.currentNextPage = 0;
34
33
  this._seenPages = [0];
35
34
  this.subWizards = [];
@@ -48,12 +47,12 @@ export default class Wizard extends Webform {
48
47
  }
49
48
  getPages(args = {}) {
50
49
  const { all = false } = args;
51
- const pages = this.hasExtraPages ? this.components : this.pages;
50
+ const pages = this.hasSubWizards ? this.components : this.pages;
52
51
  const filteredPages = pages
53
52
  .filter(all ? _.identity : (p, index) => this._seenPages.includes(index));
54
53
  return filteredPages;
55
54
  }
56
- get hasExtraPages() {
55
+ get hasSubWizards() {
57
56
  return !_.isEmpty(this.subWizards);
58
57
  }
59
58
  get data() {
@@ -177,9 +176,9 @@ export default class Wizard extends Webform {
177
176
  }
178
177
  render() {
179
178
  const ctx = this.renderContext;
180
- if (this.component.key) {
181
- ctx.panels.map(panel => {
182
- if (panel.key === this.component.key) {
179
+ if (this.component.id) {
180
+ ctx.panels.forEach(panel => {
181
+ if (panel.id === this.component.id) {
183
182
  this.currentPanel = panel;
184
183
  ctx.wizardPageTooltip = this.getFormattedTooltip(panel.tooltip);
185
184
  }
@@ -580,7 +579,7 @@ export default class Wizard extends Webform {
580
579
  this.pageFieldLogic(num);
581
580
  this.getNextPage();
582
581
  let parentNum = num;
583
- if (this.hasExtraPages) {
582
+ if (this.hasSubWizards) {
584
583
  const pageFromPages = this.pages[num];
585
584
  const pageFromComponents = this.components[num];
586
585
  if (!pageFromComponents || pageFromPages?.id !== pageFromComponents.id) {
@@ -869,23 +868,18 @@ export default class Wizard extends Webform {
869
868
  this.showErrors(errors, true, true);
870
869
  }
871
870
  // If the pages change, need to redraw the header.
872
- let currentPanels;
873
- let panels;
871
+ const currentPanels = this.pages;
872
+ // calling this.establishPages() updates/mutates this.pages to be the current pages
873
+ this.establishPages();
874
+ const newPanels = this.pages;
874
875
  const currentNextPage = this.currentNextPage;
875
- if (this.hasExtraPages) {
876
- currentPanels = this.pages.map(page => page.component.key);
877
- this.establishPages();
878
- panels = this.pages.map(page => page.component.key);
879
- }
880
- else {
881
- currentPanels = this.currentPanels || this.pages.map(page => page.component.key);
882
- panels = this.establishPages().map(panel => panel.key);
883
- this.currentPanels = panels;
884
- if (this.currentPanel?.key && this.currentPanels?.length) {
885
- this.setPage(this.currentPanels.findIndex(panel => panel === this.currentPanel.key));
886
- }
876
+ const panelsUpdated = !_.isEqual(newPanels, currentPanels);
877
+ if (this.currentPanel?.id && this.pages.length && (!this.hasSubWizards || (this.hasSubWizards && panelsUpdated))) {
878
+ const newIndex = this.pages.findIndex(page => page.id === this.currentPanel.id);
879
+ if (newIndex !== -1)
880
+ this.setPage(newIndex);
887
881
  }
888
- if (!_.isEqual(panels, currentPanels) || (flags && flags.fromSubmission)) {
882
+ if (panelsUpdated || (flags && flags.fromSubmission)) {
889
883
  this.redrawHeader();
890
884
  }
891
885
  // If the next page changes, then make sure to redraw navigation.
@@ -54,7 +54,7 @@ export default class Components {
54
54
  // eslint-disable-next-line new-cap
55
55
  comp = new Components.components['datagrid'](component, options, data);
56
56
  }
57
- else if (component.tree) {
57
+ else if (component.tree || (component.input && Array.isArray(component.components))) {
58
58
  // eslint-disable-next-line new-cap
59
59
  comp = new Components.components['nesteddata'](component, options, data);
60
60
  }
@@ -72,6 +72,12 @@ export default class Components {
72
72
  if (comp.path) {
73
73
  comp.componentsMap[comp.path] = comp;
74
74
  }
75
+ // Reset the componentMatches on the root element if any new component is created.
76
+ let parent = comp.parent;
77
+ while (parent) {
78
+ parent.componentMatches = {};
79
+ parent = parent.parent;
80
+ }
75
81
  return comp;
76
82
  }
77
83
  }
@@ -165,10 +165,16 @@ declare class Component extends Element {
165
165
  get componentsMap(): object;
166
166
  /**
167
167
  * Returns if the parent should conditionally clear.
168
+ *
168
169
  * @returns {boolean} - If the parent should conditionally clear.
169
170
  */
170
171
  parentShouldConditionallyClear(): boolean;
171
172
  parentConditionallyHidden(): boolean;
173
+ /**
174
+ * Returns true if any of the parents default their component "hidden" property to true.
175
+ * @returns {boolean} - If any parent defaults the hidden property to true.
176
+ */
177
+ anyParentDefaultsHidden(): boolean;
172
178
  set data(value: any);
173
179
  get data(): any;
174
180
  mergeSchema(component?: {}): any;
@@ -232,8 +238,23 @@ declare class Component extends Element {
232
238
  get visible(): boolean;
233
239
  get logicallyHidden(): any;
234
240
  _logicallyHidden: any;
235
- shouldConditionallyClear(skipParent?: boolean): boolean;
236
- conditionallyHidden(skipParent?: boolean): boolean;
241
+ /**
242
+ * Determines if the component should clear its value when the root form is pristine.
243
+ * @returns {boolean} - If the component should clear its value when the root form is pristine.
244
+ */
245
+ shouldConditionallyClearOnPristine(): boolean;
246
+ /**
247
+ * Returns if the component should clear its value when conditionally hidden.
248
+ * @returns {boolean} - If the component should clear its value when conditionally hidden.
249
+ */
250
+ shouldConditionallyClear(): boolean;
251
+ _conditionallyClear: boolean | undefined;
252
+ /**
253
+ * Returns if the component is conditionally hidden.
254
+ * @returns {boolean} - If the component is conditionally hidden.
255
+ */
256
+ conditionallyHidden(): boolean;
257
+ _conditionallyHidden: boolean | undefined;
237
258
  set currentForm(instance: any);
238
259
  get currentForm(): any;
239
260
  _currentForm: any;
@@ -420,12 +420,14 @@ export default class Component extends Element {
420
420
  }
421
421
  /**
422
422
  * Returns if the parent should conditionally clear.
423
+ *
423
424
  * @returns {boolean} - If the parent should conditionally clear.
424
425
  */
425
426
  parentShouldConditionallyClear() {
426
427
  let currentParent = this.parent;
427
428
  while (currentParent) {
428
- if (currentParent.shouldConditionallyClear(true)) {
429
+ if ((currentParent.allowData && currentParent._conditionallyClear) ||
430
+ (!currentParent.allowData && currentParent._conditionallyHidden)) {
429
431
  return true;
430
432
  }
431
433
  currentParent = currentParent.parent;
@@ -435,7 +437,21 @@ export default class Component extends Element {
435
437
  parentConditionallyHidden() {
436
438
  let currentParent = this.parent;
437
439
  while (currentParent) {
438
- if (currentParent.conditionallyHidden(true)) {
440
+ if (currentParent._conditionallyHidden) {
441
+ return true;
442
+ }
443
+ currentParent = currentParent.parent;
444
+ }
445
+ return false;
446
+ }
447
+ /**
448
+ * Returns true if any of the parents default their component "hidden" property to true.
449
+ * @returns {boolean} - If any parent defaults the hidden property to true.
450
+ */
451
+ anyParentDefaultsHidden() {
452
+ let currentParent = this.parent;
453
+ while (currentParent) {
454
+ if (currentParent.component.hidden) {
439
455
  return true;
440
456
  }
441
457
  currentParent = currentParent.parent;
@@ -650,48 +666,58 @@ export default class Component extends Element {
650
666
  }
651
667
  return this._logicallyHidden;
652
668
  }
653
- shouldConditionallyClear(skipParent = false) {
669
+ /**
670
+ * Determines if the component should clear its value when the root form is pristine.
671
+ * @returns {boolean} - If the component should clear its value when the root form is pristine.
672
+ */
673
+ shouldConditionallyClearOnPristine() {
674
+ // If the form is pristine, we should NOT clear the value of a conditionally hidden child component
675
+ // of a layout component that defaults to hidden using the "hidden" component property.
676
+ return !this.anyParentDefaultsHidden();
677
+ }
678
+ /**
679
+ * Returns if the component should clear its value when conditionally hidden.
680
+ * @returns {boolean} - If the component should clear its value when conditionally hidden.
681
+ */
682
+ shouldConditionallyClear() {
654
683
  // Skip if this component has clearOnHide set to false.
655
684
  if (this.component.clearOnHide === false) {
656
- return false;
685
+ this._conditionallyClear = false;
686
+ return this._conditionallyClear;
657
687
  }
658
688
  // If the component is logically hidden, then it is conditionally hidden and should clear.
659
689
  if (this.logicallyHidden) {
660
- return true;
690
+ this._conditionallyClear = true;
691
+ return this._conditionallyClear;
661
692
  }
662
693
  // If we have a condition and it is not conditionally visible, the it should conditionally clear.
663
- if (this.hasCondition() && !this.conditionallyVisible()) {
664
- return true;
665
- }
666
- if (skipParent) {
667
- // Stop recurrsion for the parent checks.
668
- return false;
669
- }
670
- // If this component has a set value, then it should ONLY clear if a parent is hidden
671
- // and has the clearOnHide set to true.
672
- if (this.hasSetValue) {
673
- return this.parentShouldConditionallyClear();
694
+ if (this.hasCondition() &&
695
+ !this.conditionallyVisible() &&
696
+ (!this.rootPristine || this.shouldConditionallyClearOnPristine())) {
697
+ this._conditionallyClear = true;
698
+ return this._conditionallyClear;
674
699
  }
675
- // Clear the value if the parent is conditionally hidden.
676
- return this.parentConditionallyHidden();
700
+ this._conditionallyClear = this.hasSetValue ? false : this.parentShouldConditionallyClear();
701
+ return this._conditionallyClear;
677
702
  }
678
- conditionallyHidden(skipParent = false) {
703
+ /**
704
+ * Returns if the component is conditionally hidden.
705
+ * @returns {boolean} - If the component is conditionally hidden.
706
+ */
707
+ conditionallyHidden() {
708
+ // If it is logically hidden, then it is conditionally hidden.
679
709
  if (this.logicallyHidden) {
680
- return true;
710
+ this._conditionallyHidden = true;
711
+ return this._conditionallyHidden;
681
712
  }
682
- if (!this.hasCondition() && !skipParent) {
683
- return this.parentConditionallyHidden();
684
- }
685
- // Return if we are not conditionally visible (conditionallyHidden)
686
- if (!this.conditionallyVisible()) {
687
- return true;
688
- }
689
- if (skipParent) {
690
- // Stop recurrsion for the parent checks.
691
- return false;
713
+ // If it has a condition, and is not conditionally visible, then it is conditionally hidden.
714
+ if (this.hasCondition() && !this.conditionallyVisible()) {
715
+ this._conditionallyHidden = true;
716
+ return this._conditionallyHidden;
692
717
  }
693
- // Check the parent.
694
- return this.parentConditionallyHidden();
718
+ // It is conditionally hidden if its parent is conditionally hidden.
719
+ this._conditionallyHidden = this.parentConditionallyHidden();
720
+ return this._conditionallyHidden;
695
721
  }
696
722
  get currentForm() {
697
723
  return this._currentForm;
@@ -3162,6 +3188,9 @@ export default class Component extends Element {
3162
3188
  data = data || this.rootValue;
3163
3189
  flags = flags || {};
3164
3190
  row = row || this.data;
3191
+ if (flags.noCheck) {
3192
+ return true;
3193
+ }
3165
3194
  // Some components (for legacy reasons) have calls to "checkData" in inappropriate places such
3166
3195
  // as setValue. Historically, this was bypassed by a series of cached states around the data model
3167
3196
  // which caused its own problems. We need to ensure that premium and custom components do not fall into
@@ -3176,9 +3205,6 @@ export default class Component extends Element {
3176
3205
  if (!flags.fromBlur) {
3177
3206
  this.checkRefreshOn(flags.changes, flags);
3178
3207
  }
3179
- if (flags.noCheck) {
3180
- return true;
3181
- }
3182
3208
  this.checkComponentConditions(data, flags, row);
3183
3209
  if (this.id !== flags.triggeredComponentId) {
3184
3210
  this.calculateComponentValue(data, flags, row);
@@ -108,6 +108,7 @@ export default class NestedComponent extends Field {
108
108
  * @returns {any} - The component that is located.
109
109
  */
110
110
  getComponent(path: string): any;
111
+ componentMatches: {} | undefined;
111
112
  /**
112
113
  * Return a component provided the Id of the component.
113
114
  * @param {string} id - The Id of the component.
@@ -308,6 +308,13 @@ export default class NestedComponent extends Field {
308
308
  * @returns {any} - The component that is located.
309
309
  */
310
310
  getComponent(path) {
311
+ // If the component is found
312
+ if (!this.componentMatches) {
313
+ this.componentMatches = {};
314
+ }
315
+ if (this.componentMatches && this.componentMatches[path]) {
316
+ return this.componentMatches[path];
317
+ }
311
318
  path = FormioUtils.getStringFromComponentPath(path);
312
319
  const matches = {
313
320
  path: undefined,
@@ -332,7 +339,8 @@ export default class NestedComponent extends Field {
332
339
  return match;
333
340
  });
334
341
  });
335
- return FormioUtils.getBestMatch(matches)?.instance;
342
+ this.componentMatches[path] = FormioUtils.getBestMatch(matches)?.instance;
343
+ return this.componentMatches[path];
336
344
  }
337
345
  /**
338
346
  * Return a component provided the Id of the component.
@@ -659,7 +667,7 @@ export default class NestedComponent extends Field {
659
667
  }
660
668
  validationProcessor({ scope, data, row, instance, paths }, flags) {
661
669
  const { dirty } = flags;
662
- if (this.root.hasExtraPages && this.page !== this.root.page) {
670
+ if (this.root && this.root.hasSubWizards && this.page !== this.root.page) {
663
671
  instance = this.componentsMap?.hasOwnProperty(paths.dataPath)
664
672
  ? this.componentsMap[paths.dataPath]
665
673
  : this.getComponent(paths.dataPath);
@@ -808,7 +816,7 @@ export default class NestedComponent extends Field {
808
816
  return false;
809
817
  }
810
818
  if (component.type === 'components') {
811
- if (component.tree && component.hasValue(value)) {
819
+ if ((component.tree || component.hasInput) && component.hasValue(value)) {
812
820
  return component.setValue(_.get(value, component.key), flags);
813
821
  }
814
822
  return component.setValue(value, flags);
@@ -33,7 +33,7 @@ export default class FileComponent extends Field {
33
33
  get dataReady(): Promise<any>;
34
34
  loadImage(fileInfo: any): any;
35
35
  get emptyValue(): never[];
36
- getValueAsString(value: any): any;
36
+ getValueAsString(value: any, options: any): any;
37
37
  get defaultValue(): any[];
38
38
  get hasTypes(): any;
39
39
  _fileBrowseHidden: any;
@@ -103,7 +103,12 @@ export default class FileComponent extends Field {
103
103
  get emptyValue() {
104
104
  return [];
105
105
  }
106
- getValueAsString(value) {
106
+ getValueAsString(value, options) {
107
+ if (options?.review && !this.component.uploadOnly) {
108
+ return _.map(value, (val, index) => {
109
+ return `<a href="${val.url || '#'}" target="_blank" data-path='${this.path}' data-fileindex='${index}'>${val.originalName}</a>`;
110
+ }).join(', ');
111
+ }
107
112
  if (_.isArray(value)) {
108
113
  return _.map(value, 'originalName').join(', ');
109
114
  }
@@ -98,8 +98,6 @@ export default class FormComponent extends Component {
98
98
  * @returns {void}
99
99
  */
100
100
  onSetSubFormValue(submission: object | null | undefined, flags: object | null | undefined): void;
101
- areAllComponentsEmpty(data: any): boolean;
102
- conditionallyHidden(): boolean;
103
101
  updateSubFormVisibility(): void;
104
102
  /**
105
103
  * Determines if this form is a Nested Wizard
@@ -96,6 +96,9 @@ export default class FormComponent extends Component {
96
96
  }
97
97
  return this.createSubForm();
98
98
  }
99
+ shouldConditionallyClearOnPristine() {
100
+ return !this.hasSetValue && super.shouldConditionallyClearOnPristine();
101
+ }
99
102
  get dataReady() {
100
103
  return this.subFormReady || Promise.resolve();
101
104
  }
@@ -289,11 +292,13 @@ export default class FormComponent extends Component {
289
292
  }
290
293
  this.subForm.attach(element);
291
294
  this.valueChanged = this.hasSetValue;
292
- if (!this.valueChanged && this.dataValue.state !== 'submitted') {
293
- this.setDefaultValue();
294
- }
295
- else {
296
- this.restoreValue();
295
+ if (!this.shouldConditionallyClear()) {
296
+ if (!this.valueChanged && this.dataValue.state !== 'submitted') {
297
+ this.setDefaultValue();
298
+ }
299
+ else {
300
+ this.restoreValue();
301
+ }
297
302
  }
298
303
  }
299
304
  if (!this.builderMode && this.component.modalEdit) {
@@ -409,7 +414,7 @@ export default class FormComponent extends Component {
409
414
  this.component.components = this.subForm._form?.components;
410
415
  this.component.display = this.subForm._form?.display;
411
416
  this.subForm.on('change', () => {
412
- if (this.subForm) {
417
+ if (this.subForm && !this.shouldConditionallyClear()) {
413
418
  this.dataValue = this.subForm.getValue();
414
419
  this.triggerChange({
415
420
  noEmit: true
@@ -669,20 +674,7 @@ export default class FormComponent extends Component {
669
674
  this.subForm.setValue(submission, flags);
670
675
  }
671
676
  isEmpty(value = this.dataValue) {
672
- return value === null || _.isEqual(value, this.emptyValue) || (this.areAllComponentsEmpty(value?.data) && !value?._id);
673
- }
674
- areAllComponentsEmpty(data) {
675
- let res = true;
676
- if (this.subForm) {
677
- this.subForm.everyComponent((comp) => {
678
- const componentValue = _.get(data, comp.key);
679
- res &= comp.isEmpty(componentValue);
680
- });
681
- }
682
- else {
683
- res = false;
684
- }
685
- return res;
677
+ return value === null || _.isEqual(value, this.emptyValue);
686
678
  }
687
679
  getValue() {
688
680
  if (this.subForm) {
@@ -89,6 +89,7 @@ export default class SelectComponent extends ListComponent {
89
89
  disableInfiniteScroll(): void;
90
90
  set serverCount(value: any);
91
91
  get serverCount(): any;
92
+ shouldResetChoicesItems(items: any): boolean;
92
93
  setItems(items: any, fromSearch: any): void;
93
94
  selectItems: any;
94
95
  set downloadedResources(value: any);
@@ -126,7 +127,6 @@ export default class SelectComponent extends ListComponent {
126
127
  get isLoadingAvailable(): any;
127
128
  onScroll(): void;
128
129
  attachRefreshOnBlur(): void;
129
- addPlaceholderItem(placeholderValue: any): void;
130
130
  update(): void;
131
131
  addCurrentChoices(values: any, items: any, keyValue: any): any;
132
132
  getValueAsString(data: any, options: any): any;
@@ -1,7 +1,6 @@
1
1
  import _ from 'lodash';
2
2
  import { Formio } from '../../Formio';
3
3
  import ListComponent from '../_classes/list/ListComponent';
4
- import Input from '../_classes/input/Input';
5
4
  import Form from '../../Form';
6
5
  import { getRandomComponentId, boolValue, isPromise, componentValueTypes, getComponentSavedTypes, isSelectResourceWithObjectValue, removeHTML } from '../../utils';
7
6
  import Choices from '../../utils/ChoicesWrapper';
@@ -360,6 +359,18 @@ export default class SelectComponent extends ListComponent {
360
359
  this.downloadedResources.serverCount = this.downloadedResources.length;
361
360
  this.serverCount = this.downloadedResources.length;
362
361
  }
362
+ shouldResetChoicesItems(items) {
363
+ if (this.choices._store.choices.length !== items.length) {
364
+ return true;
365
+ }
366
+ for (let item of items) {
367
+ const choicesItem = this.choices._store.choices.find((i) => i.label === item.label);
368
+ if (!choicesItem) {
369
+ return true;
370
+ }
371
+ }
372
+ return false;
373
+ }
363
374
  /* eslint-disable max-statements */
364
375
  setItems(items, fromSearch) {
365
376
  this.selectItems = items;
@@ -445,7 +456,7 @@ export default class SelectComponent extends ListComponent {
445
456
  this.addOption(itemValueAndLabel.value, itemValueAndLabel.label, {}, _.get(item, this.component.idPath, String(index)));
446
457
  });
447
458
  if (this.choices) {
448
- this.choices.setChoices(this.selectOptions, 'value', 'label', true);
459
+ this.choices.setChoices(this.selectOptions, 'value', 'label', true, true, !fromSearch && this.shouldResetChoicesItems(this.selectOptions));
449
460
  }
450
461
  else if (this.loading) {
451
462
  // Re-attach select input.
@@ -773,8 +784,8 @@ export default class SelectComponent extends ListComponent {
773
784
  removeItemButton: this.component.disabled ? false : _.get(this.component, 'removeItemButton', true),
774
785
  itemSelectText: '',
775
786
  classNames: {
776
- containerOuter: 'choices form-group formio-choices',
777
- containerInner: this.transform('class', 'form-control ui fluid selection dropdown')
787
+ containerOuter: ['choices', 'form-group', 'formio-choices'],
788
+ containerInner: this.transform('class', 'form-control ui fluid selection dropdown').split(' '),
778
789
  },
779
790
  addItemText: false,
780
791
  allowHTML: true,
@@ -802,6 +813,7 @@ export default class SelectComponent extends ListComponent {
802
813
  }),
803
814
  valueComparer: _.isEqual,
804
815
  resetScrollPosition: false,
816
+ duplicateItemsAllowed: false,
805
817
  ...customOptions,
806
818
  };
807
819
  }
@@ -868,7 +880,7 @@ export default class SelectComponent extends ListComponent {
868
880
  this.choices.containerOuter.element.setAttribute('tabIndex', '-1');
869
881
  this.addEventListener(this.choices.containerOuter.element, 'focus', () => this.focusableElement.focus());
870
882
  }
871
- Input.prototype.addFocusBlurEvents.call(this, this.focusableElement);
883
+ this.addFocusBlurEvents(this.choices.input.element);
872
884
  if (this.itemsFromUrl && !this.component.noRefreshOnScroll) {
873
885
  this.scrollList = this.choices.choiceList.element;
874
886
  this.addEventListener(this.scrollList, 'scroll', () => this.onScroll());
@@ -934,12 +946,6 @@ export default class SelectComponent extends ListComponent {
934
946
  this.positionDropdown();
935
947
  });
936
948
  }
937
- if (this.choices && choicesOptions.placeholderValue && this.choices._isSelectOneElement) {
938
- this.addPlaceholderItem(choicesOptions.placeholderValue);
939
- this.addEventListener(input, 'removeItem', () => {
940
- this.addPlaceholderItem(choicesOptions.placeholderValue);
941
- });
942
- }
943
949
  // Add value options.
944
950
  this.addValueOptions();
945
951
  this.setChoicesValue(this.dataValue);
@@ -1025,20 +1031,6 @@ export default class SelectComponent extends ListComponent {
1025
1031
  });
1026
1032
  }
1027
1033
  }
1028
- addPlaceholderItem(placeholderValue) {
1029
- const items = this.choices._store.activeItems;
1030
- if (!items.length) {
1031
- this.choices._addItem({
1032
- value: '',
1033
- label: placeholderValue,
1034
- choiceId: 0,
1035
- groupId: -1,
1036
- customProperties: null,
1037
- placeholder: true,
1038
- keyCode: null
1039
- });
1040
- }
1041
- }
1042
1034
  /* eslint-enable max-statements */
1043
1035
  update() {
1044
1036
  if (this.component.dataSrc === 'custom') {
@@ -24,4 +24,4 @@ export default class TagsComponent extends Input {
24
24
  getValueAsString(value: any): any;
25
25
  }
26
26
  import Input from '../_classes/input/Input';
27
- import Choices from '@formio/choices.js';
27
+ import Choices from 'choices.js';
@@ -1,6 +1,6 @@
1
1
  import { componentValueTypes, getComponentSavedTypes } from '../../utils';
2
2
  import Input from '../_classes/input/Input';
3
- import Choices from '@formio/choices.js';
3
+ import Choices from 'choices.js';
4
4
  export default class TagsComponent extends Input {
5
5
  static schema(...extend) {
6
6
  return Input.schema({
@@ -127,7 +127,7 @@ export default class TagsComponent extends Input {
127
127
  const changed = super.setValue(value, flags);
128
128
  if (this.choices) {
129
129
  let dataValue = this.dataValue;
130
- this.choices.removeActiveItems();
130
+ this.choices.clearStore();
131
131
  if (dataValue) {
132
132
  if (typeof dataValue === 'string') {
133
133
  dataValue = dataValue.split(this.delimiter).filter(result => result);
@@ -56,6 +56,7 @@ export function registerModule(mod, defaultFn = null, options = {}) {
56
56
  case 'templates':
57
57
  for (const framework of Object.keys(mod.templates)) {
58
58
  Formio.Templates.extendTemplate(framework, mod.templates[framework]);
59
+ Formio.Templates.defaultTemplates = _.defaults(mod.templates[framework], Formio.Templates.defaultTemplates);
59
60
  }
60
61
  if (mod.templates[current]) {
61
62
  Formio.Templates.current = mod.templates[current];
@@ -1,38 +1,17 @@
1
- export namespace KEY_CODES {
2
- let BACK_KEY: number;
3
- let DELETE_KEY: number;
4
- let TAB_KEY: number;
5
- let ENTER_KEY: number;
6
- let A_KEY: number;
7
- let ESC_KEY: number;
8
- let UP_KEY: number;
9
- let DOWN_KEY: number;
10
- let PAGE_UP_KEY: number;
11
- let PAGE_DOWN_KEY: number;
12
- }
13
1
  export default ChoicesWrapper;
14
2
  declare class ChoicesWrapper extends Choices {
15
3
  constructor(...args: any[]);
16
- _onTabKey({ activeItems, hasActiveDropdown }: {
17
- activeItems: any;
18
- hasActiveDropdown: any;
19
- }): void;
4
+ _onTabKey(): void;
20
5
  isDirectionUsing: boolean;
21
6
  shouldOpenDropDown: boolean;
22
7
  _onTouchEnd(event: any): void;
23
- _handleButtonAction(activeItems: any, element: any): void;
24
- _onEnterKey(args: any): void;
8
+ _onEnterKey(...args: any[]): void;
25
9
  _onDirectionKey(...args: any[]): void;
26
10
  timeout: NodeJS.Timeout | undefined;
27
11
  _selectHighlightedChoice(): void;
28
12
  _onKeyDown(event: any): void;
29
- onSelectValue({ event, activeItems, hasActiveDropdown }: {
30
- event: any;
31
- activeItems: any;
32
- hasActiveDropdown: any;
33
- }): void;
13
+ onSelectValue(event: any, hasActiveDropdown: any): void;
34
14
  showDropdown(...args: any[]): void;
35
15
  hideDropdown(...args: any[]): void;
36
- _onBlur(...args: any[]): void;
37
16
  }
38
- import Choices from '@formio/choices.js';
17
+ import Choices from 'choices.js';