@formio/js 5.1.0-rc.25 → 5.1.0-rc.26

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 (46) hide show
  1. package/dist/formio.embed.js +1 -1
  2. package/dist/formio.embed.min.js +1 -1
  3. package/dist/formio.embed.min.js.LICENSE.txt +1 -1
  4. package/dist/formio.form.js +9 -9
  5. package/dist/formio.form.min.js +1 -1
  6. package/dist/formio.form.min.js.LICENSE.txt +1 -1
  7. package/dist/formio.full.js +11 -11
  8. package/dist/formio.full.min.js +1 -1
  9. package/dist/formio.full.min.js.LICENSE.txt +1 -1
  10. package/dist/formio.js +2 -2
  11. package/dist/formio.min.js +1 -1
  12. package/dist/formio.min.js.LICENSE.txt +1 -1
  13. package/dist/formio.utils.min.js.LICENSE.txt +1 -1
  14. package/lib/cjs/Embed.js +1 -1
  15. package/lib/cjs/Formio.js +1 -1
  16. package/lib/cjs/Wizard.d.ts +1 -0
  17. package/lib/cjs/Wizard.js +17 -0
  18. package/lib/cjs/components/_classes/component/Component.d.ts +7 -11
  19. package/lib/cjs/components/_classes/component/Component.js +28 -26
  20. package/lib/cjs/components/_classes/nested/NestedComponent.js +8 -1
  21. package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.d.ts +0 -2
  22. package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.js +0 -11
  23. package/lib/cjs/components/address/Address.d.ts +8 -0
  24. package/lib/cjs/components/address/Address.js +18 -8
  25. package/lib/cjs/components/address/editForm/Address.edit.provider.js +8 -8
  26. package/lib/cjs/components/file/editForm/File.edit.file.d.ts +13 -0
  27. package/lib/cjs/components/file/editForm/File.edit.file.js +1 -0
  28. package/lib/cjs/components/form/Form.js +4 -0
  29. package/lib/cjs/components/selectboxes/SelectBoxes.js +3 -0
  30. package/lib/mjs/Embed.js +1 -1
  31. package/lib/mjs/Formio.js +1 -1
  32. package/lib/mjs/Wizard.d.ts +1 -0
  33. package/lib/mjs/Wizard.js +17 -0
  34. package/lib/mjs/components/_classes/component/Component.d.ts +7 -11
  35. package/lib/mjs/components/_classes/component/Component.js +28 -26
  36. package/lib/mjs/components/_classes/nested/NestedComponent.js +8 -1
  37. package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.d.ts +0 -2
  38. package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +0 -11
  39. package/lib/mjs/components/address/Address.d.ts +8 -0
  40. package/lib/mjs/components/address/Address.js +18 -8
  41. package/lib/mjs/components/address/editForm/Address.edit.provider.js +8 -8
  42. package/lib/mjs/components/file/editForm/File.edit.file.d.ts +13 -0
  43. package/lib/mjs/components/file/editForm/File.edit.file.js +1 -0
  44. package/lib/mjs/components/form/Form.js +4 -0
  45. package/lib/mjs/components/selectboxes/SelectBoxes.js +3 -0
  46. package/package.json +1 -1
@@ -325,22 +325,6 @@ export default class Component extends Element {
325
325
  * The reference attribute name for this component
326
326
  */
327
327
  this._referenceAttributeName = 'ref';
328
- /**
329
- * Sometimes the customDefaultValue does not set the "value" within the script, but is just a script to execute. This
330
- * flag is used to determine if the customDefaultValue should be used to set the value of the component or not based on
331
- * if there is a "value=" within the script.
332
- */
333
- this.shouldSetCustomDefault = true;
334
- if (this.component.customDefaultValue && (typeof this.component.customDefaultValue === 'string')) {
335
- this.shouldSetCustomDefault = this.component.customDefaultValue.match(/value\s*=/);
336
- }
337
- /**
338
- * Same as customDefaultValue, but for calculateValue.
339
- */
340
- this.shouldSetCalculatedValue = true;
341
- if (this.component.calculateValue && (typeof this.component.calculateValue === 'string')) {
342
- this.shouldSetCalculatedValue = this.component.calculateValue.match(/value\s*=/);
343
- }
344
328
  /**
345
329
  * Used to trigger a new change in this component.
346
330
  * @type {Function} - Call to trigger a change in this component.
@@ -2509,15 +2493,27 @@ export default class Component extends Element {
2509
2493
  }
2510
2494
  getCustomDefaultValue(defaultValue) {
2511
2495
  if (this.component.customDefaultValue && !this.options.preview) {
2512
- const customDefaultValue = this.evaluate(this.component.customDefaultValue, { value: '' }, 'value');
2513
- if (this.shouldSetCustomDefault) {
2514
- defaultValue = customDefaultValue;
2515
- }
2496
+ defaultValue = this.evaluate(this.component.customDefaultValue, { value: this.dataValue }, 'value');
2516
2497
  }
2517
2498
  return defaultValue;
2518
2499
  }
2500
+ /**
2501
+ * Returns if a component has a default value set.
2502
+ * @returns {boolean} - TRUE if a default value is set.
2503
+ */
2504
+ get hasDefaultValue() {
2505
+ return this.component.customDefaultValue || (this.component.hasOwnProperty('defaultValue') &&
2506
+ (this.component.defaultValue !== null) &&
2507
+ (this.component.defaultValue !== undefined));
2508
+ }
2519
2509
  get shouldAddDefaultValue() {
2520
- return !this.options.noDefaults || (this.component.defaultValue && !this.isEmpty(this.component.defaultValue)) || this.component.customDefaultValue;
2510
+ // It should add a default value if...
2511
+ // 1.) Ensure they have not set "noDefaults". If that is true, then will always return false. AND
2512
+ // 2.) The component is pristine (user has not manually modified it). AND
2513
+ // 3.) There is a default value setting present and it is not NULL or UNDEFINED.
2514
+ return !this.options.noDefaults && this.pristine && (this.hasDefaultValue ||
2515
+ // Empty strings and booleans are allowed primitives whose defaults are automatically added.
2516
+ (this.emptyValue === '' || (typeof this.emptyValue === 'boolean')));
2521
2517
  }
2522
2518
  get defaultValue() {
2523
2519
  let defaultValue = this.emptyValue;
@@ -2771,7 +2767,7 @@ export default class Component extends Element {
2771
2767
  return value;
2772
2768
  }
2773
2769
  doValueCalculation(dataValue, data, row) {
2774
- const calculatedValue = this.evaluate(this.component.calculateValue, {
2770
+ return this.evaluate(this.component.calculateValue, {
2775
2771
  value: dataValue,
2776
2772
  data,
2777
2773
  row: row || this.data,
@@ -2779,10 +2775,6 @@ export default class Component extends Element {
2779
2775
  data: this.rootValue
2780
2776
  }
2781
2777
  }, 'value');
2782
- if (this.shouldSetCalculatedValue) {
2783
- return calculatedValue;
2784
- }
2785
- return dataValue;
2786
2778
  }
2787
2779
  /* eslint-disable max-statements */
2788
2780
  calculateComponentValue(data, flags, row) {
@@ -3112,6 +3104,14 @@ export default class Component extends Element {
3112
3104
  data = data || this.rootValue;
3113
3105
  flags = flags || {};
3114
3106
  row = row || this.data;
3107
+ // Some components (for legacy reasons) have calls to "checkData" in inappropriate places such
3108
+ // as setValue. Historically, this was bypassed by a series of cached states around the data model
3109
+ // which caused its own problems. We need to ensure that premium and custom components do not fall into
3110
+ // an infinite loop by only checking this component once.
3111
+ if (this.checkingData) {
3112
+ return;
3113
+ }
3114
+ this.checkingData = true;
3115
3115
  // Needs for Nextgen Rules Engine
3116
3116
  this.resetCaches();
3117
3117
  // Do not trigger refresh if change was triggered on blur event since components with Refresh on Blur have their own listeners
@@ -3125,6 +3125,8 @@ export default class Component extends Element {
3125
3125
  if (this.id !== flags.triggeredComponentId) {
3126
3126
  this.calculateComponentValue(data, flags, row);
3127
3127
  }
3128
+ // We are done checking data.
3129
+ this.checkingData = false;
3128
3130
  }
3129
3131
  checkModal(errors = [], dirty = false) {
3130
3132
  const messages = errors.filter(error => !error.fromServer);
@@ -816,7 +816,7 @@ export default class NestedComponent extends Field {
816
816
  else if (value && component.hasValue(value)) {
817
817
  return component.setValue(_.get(value, component.key), flags);
818
818
  }
819
- else if ((!this.rootPristine || component.visible) && component.shouldAddDefaultValue) {
819
+ else if ((!this.rootPristine || component.visible) && (flags.resetValue || component.shouldAddDefaultValue)) {
820
820
  flags.noValidate = !flags.dirty;
821
821
  flags.resetValue = true;
822
822
  return component.setValue(component.defaultValue, flags);
@@ -826,6 +826,13 @@ export default class NestedComponent extends Field {
826
826
  if (!value) {
827
827
  return false;
828
828
  }
829
+ // If the value is equal to the empty value, then this means we need to reset the values.
830
+ if (_.isEqual(value, this.emptyValue)) {
831
+ // TO-DO: For a future major release, we need to investigate removing the need for the
832
+ // "resetValue" flag. This seems like a hack that is no longer necessary and the renderer
833
+ // may behave more deterministically without it.
834
+ flags.resetValue = true;
835
+ }
829
836
  return this.getComponents().reduce((changed, component) => {
830
837
  return this.setNestedValue(component, value, flags, changed) || changed;
831
838
  }, false);
@@ -3,11 +3,9 @@ export default class NestedDataComponent extends NestedComponent {
3
3
  hasChanged(newValue: any, oldValue: any): boolean;
4
4
  get allowData(): boolean;
5
5
  get emptyValue(): {};
6
- get shouldAddDefaultValue(): boolean;
7
6
  componentContext(): any;
8
7
  getValueAsString(value: any, options: any): string;
9
8
  getDataValueAsTable(value: any, options: any): string;
10
- everyComponent(fn: any, options?: {}): void;
11
9
  /**
12
10
  * Get the value of this component.
13
11
  * @returns {any} - Return the value of this component.
@@ -90,17 +90,6 @@ export default class NestedDataComponent extends NestedComponent {
90
90
  `);
91
91
  return result;
92
92
  }
93
- everyComponent(fn, options = {}) {
94
- if (options?.email) {
95
- if (options.fromRoot) {
96
- delete options.fromRoot;
97
- }
98
- else {
99
- return;
100
- }
101
- }
102
- return super.everyComponent(fn, options);
103
- }
104
93
  /**
105
94
  * Get the value of this component.
106
95
  * @returns {any} - Return the value of this component.
@@ -43,6 +43,14 @@ export default class AddressComponent extends ContainerComponent {
43
43
  isValueInLegacyFormat(value: any): any;
44
44
  normalizeValue(value: any): any;
45
45
  get modeSwitcher(): any;
46
+ get providerOptions(): {
47
+ params: any;
48
+ url: any;
49
+ queryProperty: any;
50
+ responseProperty: any;
51
+ displayValueProperty: any;
52
+ autocompleteOptions: any;
53
+ };
46
54
  get removeValueIcon(): any;
47
55
  get searchInput(): any;
48
56
  get addRowButton(): any;
@@ -20,7 +20,6 @@ export default class AddressComponent extends ContainerComponent {
20
20
  key: 'address',
21
21
  switchToManualModeLabel: 'Can\'t find address? Switch to manual mode.',
22
22
  provider: '',
23
- providerOptions: {},
24
23
  manualModeViewString: '',
25
24
  hideLabel: false,
26
25
  disableClearIcon: false,
@@ -113,20 +112,20 @@ export default class AddressComponent extends ContainerComponent {
113
112
  NestedComponent.prototype.addComponents.call(this, this.manualMode ? this.address : {});
114
113
  }
115
114
  Field.prototype.init.call(this);
115
+ let provider = this.component.provider;
116
+ const providerOptions = this.providerOptions;
117
+ const map = this.component.map;
116
118
  if (!this.builderMode) {
117
- if (this.component.provider) {
118
- const { provider, providerOptions, } = this.component;
119
+ if (provider) {
119
120
  if (_.get(providerOptions, 'params.subscriptionKey')) {
120
121
  _.set(providerOptions, "params['subscription-key']", _.get(providerOptions, 'params.subscriptionKey'));
121
122
  _.unset(providerOptions, 'params.subscriptionKey');
122
123
  }
123
124
  this.provider = this.initializeProvider(provider, providerOptions);
124
125
  }
125
- else if (this.component.map) {
126
+ else if (map) {
126
127
  // Fallback to legacy version where Google Maps was the only provider.
127
- this.component.provider = GoogleAddressProvider.name;
128
- this.component.providerOptions = this.component.providerOptions || {};
129
- const { map, provider, providerOptions, } = this.component;
128
+ provider = this.component.provider = GoogleAddressProvider.name;
130
129
  const { key, region, } = map;
131
130
  if (key) {
132
131
  _.set(providerOptions, 'params.key', key);
@@ -258,6 +257,16 @@ export default class AddressComponent extends ContainerComponent {
258
257
  ? (this.refs[AddressComponent.modeSwitcherRef] || null)
259
258
  : null;
260
259
  }
260
+ get providerOptions() {
261
+ return {
262
+ params: { subscriptionKey: this.component.subscriptionKey, key: this.component.apiKey, ...this.component.params },
263
+ url: this.component.url,
264
+ queryProperty: this.component.queryProperty,
265
+ responseProperty: this.component.responseProperty,
266
+ displayValueProperty: this.component.displayValueProperty,
267
+ autocompleteOptions: this.component.autocompleteOptions
268
+ };
269
+ }
261
270
  get removeValueIcon() {
262
271
  return this.refs
263
272
  ? (this.refs[AddressComponent.removeValueIconRef] || null)
@@ -371,7 +380,8 @@ export default class AddressComponent extends ContainerComponent {
371
380
  const result = ((this.builderMode || this.manualMode) ? super.attach : Field.prototype.attach).call(this, element);
372
381
  if (!this.builderMode) {
373
382
  if (!this.provider && this.component.provider) {
374
- const { provider, providerOptions, } = this.component;
383
+ const provider = this.component.provider;
384
+ const providerOptions = this.providerOptions;
375
385
  this.provider = this.initializeProvider(provider, providerOptions);
376
386
  }
377
387
  }
@@ -26,7 +26,7 @@ export default [
26
26
  {
27
27
  type: 'textfield',
28
28
  input: true,
29
- key: "providerOptions.params.subscriptionKey",
29
+ key: "subscriptionKey",
30
30
  label: 'Subscription Key',
31
31
  placeholder: 'Enter Subscription Key',
32
32
  weight: 10,
@@ -41,7 +41,7 @@ export default [
41
41
  {
42
42
  type: 'textfield',
43
43
  input: true,
44
- key: 'providerOptions.url',
44
+ key: 'url',
45
45
  label: 'Url',
46
46
  placeholder: 'Enter Url',
47
47
  weight: 10,
@@ -56,7 +56,7 @@ export default [
56
56
  {
57
57
  type: 'textfield',
58
58
  input: true,
59
- key: 'providerOptions.queryProperty',
59
+ key: 'queryProperty',
60
60
  label: 'Query Property',
61
61
  defaultValue: 'query',
62
62
  placeholder: 'Enter Query Property',
@@ -69,7 +69,7 @@ export default [
69
69
  {
70
70
  type: 'textfield',
71
71
  input: true,
72
- key: 'providerOptions.responseProperty',
72
+ key: 'responseProperty',
73
73
  label: 'Response Property',
74
74
  placeholder: 'Enter Response Property',
75
75
  weight: 30,
@@ -81,7 +81,7 @@ export default [
81
81
  {
82
82
  type: 'textfield',
83
83
  input: true,
84
- key: 'providerOptions.displayValueProperty',
84
+ key: 'displayValueProperty',
85
85
  label: 'Display Value Property',
86
86
  placeholder: 'Display Value Property',
87
87
  weight: 40,
@@ -93,7 +93,7 @@ export default [
93
93
  {
94
94
  type: 'textarea',
95
95
  input: true,
96
- key: 'providerOptions.params',
96
+ key: 'params',
97
97
  label: 'Params',
98
98
  placeholder: '{ ... }',
99
99
  weight: 50,
@@ -108,7 +108,7 @@ export default [
108
108
  {
109
109
  type: 'textfield',
110
110
  input: true,
111
- key: 'providerOptions.params.key',
111
+ key: 'apiKey',
112
112
  label: 'API Key',
113
113
  placeholder: 'Enter API Key',
114
114
  weight: 10,
@@ -123,7 +123,7 @@ export default [
123
123
  {
124
124
  type: 'textarea',
125
125
  input: true,
126
- key: 'providerOptions.params.autocompleteOptions',
126
+ key: 'autocompleteOptions',
127
127
  label: 'Provider options',
128
128
  placeholder: 'Enter provider options as JSON object',
129
129
  defaultValue: {},
@@ -16,6 +16,7 @@ declare const _default: ({
16
16
  components?: undefined;
17
17
  rows?: undefined;
18
18
  editor?: undefined;
19
+ as?: undefined;
19
20
  optionsLabelPosition?: undefined;
20
21
  inline?: undefined;
21
22
  defaultValue?: undefined;
@@ -45,6 +46,7 @@ declare const _default: ({
45
46
  components?: undefined;
46
47
  rows?: undefined;
47
48
  editor?: undefined;
49
+ as?: undefined;
48
50
  optionsLabelPosition?: undefined;
49
51
  inline?: undefined;
50
52
  defaultValue?: undefined;
@@ -91,6 +93,7 @@ declare const _default: ({
91
93
  data?: undefined;
92
94
  rows?: undefined;
93
95
  editor?: undefined;
96
+ as?: undefined;
94
97
  optionsLabelPosition?: undefined;
95
98
  inline?: undefined;
96
99
  defaultValue?: undefined;
@@ -120,6 +123,7 @@ declare const _default: ({
120
123
  components?: undefined;
121
124
  rows?: undefined;
122
125
  editor?: undefined;
126
+ as?: undefined;
123
127
  optionsLabelPosition?: undefined;
124
128
  inline?: undefined;
125
129
  defaultValue?: undefined;
@@ -149,6 +153,7 @@ declare const _default: ({
149
153
  components?: undefined;
150
154
  rows?: undefined;
151
155
  editor?: undefined;
156
+ as?: undefined;
152
157
  optionsLabelPosition?: undefined;
153
158
  inline?: undefined;
154
159
  defaultValue?: undefined;
@@ -160,6 +165,7 @@ declare const _default: ({
160
165
  tooltip: string;
161
166
  rows: number;
162
167
  editor: string;
168
+ as: string;
163
169
  input: boolean;
164
170
  weight: number;
165
171
  placeholder: string;
@@ -207,6 +213,7 @@ declare const _default: ({
207
213
  components?: undefined;
208
214
  rows?: undefined;
209
215
  editor?: undefined;
216
+ as?: undefined;
210
217
  optionsLabelPosition?: undefined;
211
218
  inline?: undefined;
212
219
  defaultValue?: undefined;
@@ -227,6 +234,7 @@ declare const _default: ({
227
234
  components?: undefined;
228
235
  rows?: undefined;
229
236
  editor?: undefined;
237
+ as?: undefined;
230
238
  optionsLabelPosition?: undefined;
231
239
  inline?: undefined;
232
240
  defaultValue?: undefined;
@@ -247,6 +255,7 @@ declare const _default: ({
247
255
  components?: undefined;
248
256
  rows?: undefined;
249
257
  editor?: undefined;
258
+ as?: undefined;
250
259
  optionsLabelPosition?: undefined;
251
260
  inline?: undefined;
252
261
  defaultValue?: undefined;
@@ -276,6 +285,7 @@ declare const _default: ({
276
285
  components?: undefined;
277
286
  rows?: undefined;
278
287
  editor?: undefined;
288
+ as?: undefined;
279
289
  optionsLabelPosition?: undefined;
280
290
  inline?: undefined;
281
291
  defaultValue?: undefined;
@@ -305,6 +315,7 @@ declare const _default: ({
305
315
  components?: undefined;
306
316
  rows?: undefined;
307
317
  editor?: undefined;
318
+ as?: undefined;
308
319
  optionsLabelPosition?: undefined;
309
320
  inline?: undefined;
310
321
  defaultValue?: undefined;
@@ -332,6 +343,7 @@ declare const _default: ({
332
343
  components?: undefined;
333
344
  rows?: undefined;
334
345
  editor?: undefined;
346
+ as?: undefined;
335
347
  } | {
336
348
  type: string;
337
349
  input: boolean;
@@ -353,6 +365,7 @@ declare const _default: ({
353
365
  tableView?: undefined;
354
366
  rows?: undefined;
355
367
  editor?: undefined;
368
+ as?: undefined;
356
369
  optionsLabelPosition?: undefined;
357
370
  inline?: undefined;
358
371
  defaultValue?: undefined;
@@ -115,6 +115,7 @@ export default [
115
115
  tooltip: 'Pass your custom xhr options(optional)',
116
116
  rows: 5,
117
117
  editor: 'ace',
118
+ as: 'json',
118
119
  input: true,
119
120
  weight: 15,
120
121
  placeholder: `{
@@ -109,6 +109,10 @@ export default class FormComponent extends Component {
109
109
  get emptyValue() {
110
110
  return { data: {} };
111
111
  }
112
+ // In order for the subform values to set properly, we must always say that nested forms have a default value.
113
+ get hasDefaultValue() {
114
+ return true;
115
+ }
112
116
  get ready() {
113
117
  return this.subFormReady || Promise.resolve();
114
118
  }
@@ -66,6 +66,9 @@ export default class SelectBoxesComponent extends RadioComponent {
66
66
  info.attr.class = 'form-check-input';
67
67
  return info;
68
68
  }
69
+ get hasDefaultValue() {
70
+ return true;
71
+ }
69
72
  get emptyValue() {
70
73
  return this.component.values.reduce((prev, value) => {
71
74
  if (value.value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-rc.25",
3
+ "version": "5.1.0-rc.26",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {