@formio/js 5.1.0-dev.6162.d0510e0 → 5.1.0-dev.6166.dce1c56

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.
@@ -75,6 +75,12 @@ class Components {
75
75
  if (comp.path) {
76
76
  comp.componentsMap[comp.path] = comp;
77
77
  }
78
+ // Reset the componentMatches on the root element if any new component is created.
79
+ let parent = comp.parent;
80
+ while (parent) {
81
+ parent.componentMatches = {};
82
+ parent = parent.parent;
83
+ }
78
84
  return comp;
79
85
  }
80
86
  }
@@ -2715,6 +2715,11 @@ class Component extends Element_1.default {
2715
2715
  this.setValueAt(i, isArray && !this.isSingleInputValue() ? value[i] : value, flags);
2716
2716
  }
2717
2717
  }
2718
+ // Also reset value of the modal component, otherwise it will keep the old value locally and the preview
2719
+ // element won't refresh
2720
+ if (this.componentModal && flags && flags.resetValue) {
2721
+ this.componentModal.setValue(value);
2722
+ }
2718
2723
  return changed;
2719
2724
  }
2720
2725
  /**
@@ -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.
@@ -311,6 +311,13 @@ class NestedComponent extends Field_1.default {
311
311
  */
312
312
  getComponent(path) {
313
313
  var _a;
314
+ // If the component is found
315
+ if (!this.componentMatches) {
316
+ this.componentMatches = {};
317
+ }
318
+ if (this.componentMatches && this.componentMatches[path]) {
319
+ return this.componentMatches[path];
320
+ }
314
321
  path = utils_1.default.getStringFromComponentPath(path);
315
322
  const matches = {
316
323
  path: undefined,
@@ -336,7 +343,8 @@ class NestedComponent extends Field_1.default {
336
343
  return match;
337
344
  });
338
345
  });
339
- return (_a = utils_1.default.getBestMatch(matches)) === null || _a === void 0 ? void 0 : _a.instance;
346
+ this.componentMatches[path] = (_a = utils_1.default.getBestMatch(matches)) === null || _a === void 0 ? void 0 : _a.instance;
347
+ return this.componentMatches[path];
340
348
  }
341
349
  /**
342
350
  * Return a component provided the Id of the component.
@@ -800,8 +808,10 @@ class NestedComponent extends Field_1.default {
800
808
  return this.data;
801
809
  }
802
810
  resetValue() {
803
- super.resetValue();
811
+ // Reset values of child components first, then reset the parent one, otherwise it will restore the default
812
+ // value of parent component and clear it one by one while resetting child components
804
813
  this.getComponents().forEach((comp) => comp.resetValue());
814
+ super.resetValue();
805
815
  this.setPristine(true);
806
816
  }
807
817
  get dataReady() {
@@ -249,7 +249,7 @@ class AddressComponent extends Container_1.default {
249
249
  if (this.manualMode) {
250
250
  this.restoreComponentsContext();
251
251
  }
252
- if (changed || !lodash_1.default.isEmpty(value) && flags.fromSubmission) {
252
+ if (changed || !lodash_1.default.isEmpty(value) && flags.fromSubmission || flags.resetValue) {
253
253
  this.redraw();
254
254
  }
255
255
  return changed;
@@ -101,7 +101,6 @@ export default class EditGridComponent extends NestedArrayComponent {
101
101
  changeState(changed: any, flags: any): void;
102
102
  openWhenEmpty(): void;
103
103
  restoreRowContext(editRow: any, flags?: {}): void;
104
- emptyRows(): void;
105
104
  hasChanged: (newValue: any, oldValue: any) => boolean;
106
105
  }
107
106
  import NestedArrayComponent from '../_classes/nestedarray/NestedArrayComponent';
@@ -1200,14 +1200,6 @@ class EditGridComponent extends NestedArrayComponent_1.default {
1200
1200
  this.setNestedValue(component, editRow.data, flags);
1201
1201
  });
1202
1202
  }
1203
- emptyRows() {
1204
- this.editRows.forEach((editRow, index) => this.destroyComponents(false, index));
1205
- this.editRows = [];
1206
- }
1207
- resetValue() {
1208
- super.resetValue();
1209
- this.emptyRows();
1210
- }
1211
1203
  }
1212
1204
  exports.default = EditGridComponent;
1213
1205
  EditGridComponent.prototype.hasChanged = Component_1.default.prototype.hasChanged;
@@ -16,6 +16,7 @@ export default class RadioComponent extends ListComponent {
16
16
  static savedValueTypes(schema: any): any[];
17
17
  constructor(component: any, options: any, data: any);
18
18
  previousValue: any;
19
+ uncheckValue(flags?: {}): void;
19
20
  get inputInfo(): any;
20
21
  get emptyValue(): string;
21
22
  get isRadio(): boolean;
@@ -79,13 +79,15 @@ class RadioComponent extends ListComponent_1.default {
79
79
  }
80
80
  return defaultValue;
81
81
  }
82
- resetValue() {
82
+ uncheckValue(flags = {}) {
83
83
  this.unset();
84
84
  this.setValue(this.emptyValue, {
85
85
  noUpdateEvent: true,
86
86
  noValidate: true,
87
87
  resetValue: true
88
88
  });
89
+ this.triggerChange(flags);
90
+ this.setSelectedClasses();
89
91
  }
90
92
  get inputInfo() {
91
93
  var _a;
@@ -400,9 +402,7 @@ class RadioComponent extends ListComponent_1.default {
400
402
  this.currentValue = this.dataValue;
401
403
  const shouldResetValue = flags && flags.modified && !flags.noUpdateEvent && this.previousValue === this.currentValue;
402
404
  if (shouldResetValue) {
403
- this.resetValue();
404
- this.triggerChange(flags);
405
- this.setSelectedClasses();
405
+ this.uncheckValue(flags);
406
406
  }
407
407
  this.previousValue = this.dataValue;
408
408
  return changed;
@@ -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
  }
@@ -2707,6 +2707,11 @@ export default class Component extends Element {
2707
2707
  this.setValueAt(i, isArray && !this.isSingleInputValue() ? value[i] : value, flags);
2708
2708
  }
2709
2709
  }
2710
+ // Also reset value of the modal component, otherwise it will keep the old value locally and the preview
2711
+ // element won't refresh
2712
+ if (this.componentModal && flags && flags.resetValue) {
2713
+ this.componentModal.setValue(value);
2714
+ }
2710
2715
  return changed;
2711
2716
  }
2712
2717
  /**
@@ -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.
@@ -795,8 +803,10 @@ export default class NestedComponent extends Field {
795
803
  return this.data;
796
804
  }
797
805
  resetValue() {
798
- super.resetValue();
806
+ // Reset values of child components first, then reset the parent one, otherwise it will restore the default
807
+ // value of parent component and clear it one by one while resetting child components
799
808
  this.getComponents().forEach((comp) => comp.resetValue());
809
+ super.resetValue();
800
810
  this.setPristine(true);
801
811
  }
802
812
  get dataReady() {
@@ -245,7 +245,7 @@ export default class AddressComponent extends ContainerComponent {
245
245
  if (this.manualMode) {
246
246
  this.restoreComponentsContext();
247
247
  }
248
- if (changed || !_.isEmpty(value) && flags.fromSubmission) {
248
+ if (changed || !_.isEmpty(value) && flags.fromSubmission || flags.resetValue) {
249
249
  this.redraw();
250
250
  }
251
251
  return changed;
@@ -101,7 +101,6 @@ export default class EditGridComponent extends NestedArrayComponent {
101
101
  changeState(changed: any, flags: any): void;
102
102
  openWhenEmpty(): void;
103
103
  restoreRowContext(editRow: any, flags?: {}): void;
104
- emptyRows(): void;
105
104
  hasChanged: (newValue: any, oldValue: any) => boolean;
106
105
  }
107
106
  import NestedArrayComponent from '../_classes/nestedarray/NestedArrayComponent';
@@ -1192,13 +1192,5 @@ export default class EditGridComponent extends NestedArrayComponent {
1192
1192
  this.setNestedValue(component, editRow.data, flags);
1193
1193
  });
1194
1194
  }
1195
- emptyRows() {
1196
- this.editRows.forEach((editRow, index) => this.destroyComponents(false, index));
1197
- this.editRows = [];
1198
- }
1199
- resetValue() {
1200
- super.resetValue();
1201
- this.emptyRows();
1202
- }
1203
1195
  }
1204
1196
  EditGridComponent.prototype.hasChanged = Component.prototype.hasChanged;
@@ -16,6 +16,7 @@ export default class RadioComponent extends ListComponent {
16
16
  static savedValueTypes(schema: any): any[];
17
17
  constructor(component: any, options: any, data: any);
18
18
  previousValue: any;
19
+ uncheckValue(flags?: {}): void;
19
20
  get inputInfo(): any;
20
21
  get emptyValue(): string;
21
22
  get isRadio(): boolean;
@@ -80,13 +80,15 @@ export default class RadioComponent extends ListComponent {
80
80
  }
81
81
  return defaultValue;
82
82
  }
83
- resetValue() {
83
+ uncheckValue(flags = {}) {
84
84
  this.unset();
85
85
  this.setValue(this.emptyValue, {
86
86
  noUpdateEvent: true,
87
87
  noValidate: true,
88
88
  resetValue: true
89
89
  });
90
+ this.triggerChange(flags);
91
+ this.setSelectedClasses();
90
92
  }
91
93
  get inputInfo() {
92
94
  const info = super.elementInfo();
@@ -400,9 +402,7 @@ export default class RadioComponent extends ListComponent {
400
402
  this.currentValue = this.dataValue;
401
403
  const shouldResetValue = flags && flags.modified && !flags.noUpdateEvent && this.previousValue === this.currentValue;
402
404
  if (shouldResetValue) {
403
- this.resetValue();
404
- this.triggerChange(flags);
405
- this.setSelectedClasses();
405
+ this.uncheckValue(flags);
406
406
  }
407
407
  this.previousValue = this.dataValue;
408
408
  return changed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-dev.6162.d0510e0",
3
+ "version": "5.1.0-dev.6166.dce1c56",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {