@formio/js 5.0.0-rc.42 → 5.0.0-rc.43

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 (32) 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 +3687 -4873
  5. package/dist/formio.form.min.js +1 -1
  6. package/dist/formio.form.min.js.LICENSE.txt +2 -4
  7. package/dist/formio.full.js +4124 -5560
  8. package/dist/formio.full.min.js +1 -1
  9. package/dist/formio.full.min.js.LICENSE.txt +2 -4
  10. package/dist/formio.js +79 -89
  11. package/dist/formio.min.js +1 -1
  12. package/dist/formio.min.js.LICENSE.txt +1 -1
  13. package/dist/formio.utils.js +82 -146
  14. package/dist/formio.utils.min.js +1 -1
  15. package/dist/formio.utils.min.js.LICENSE.txt +2 -4
  16. package/lib/cjs/Webform.js +5 -7
  17. package/lib/cjs/components/_classes/component/Component.js +7 -3
  18. package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
  19. package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
  20. package/lib/cjs/components/editgrid/EditGrid.js +1 -0
  21. package/lib/cjs/components/form/Form.js +9 -6
  22. package/lib/cjs/widgets/CalendarWidget.js +3 -2
  23. package/lib/cjs/widgets/InputWidget.js +2 -2
  24. package/lib/mjs/Webform.js +5 -7
  25. package/lib/mjs/components/_classes/component/Component.js +7 -3
  26. package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
  27. package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +1 -1
  28. package/lib/mjs/components/editgrid/EditGrid.js +1 -0
  29. package/lib/mjs/components/form/Form.js +7 -4
  30. package/lib/mjs/widgets/CalendarWidget.js +3 -2
  31. package/lib/mjs/widgets/InputWidget.js +2 -2
  32. package/package.json +11 -11
@@ -10,11 +10,9 @@
10
10
  * MIT licensed
11
11
  */
12
12
 
13
- /*! @license DOMPurify 3.0.11 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.11/LICENSE */
13
+ /*! @license DOMPurify 3.1.0 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.1.0/LICENSE */
14
14
 
15
- /*! @license DOMPurify 3.0.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.6/LICENSE */
16
-
17
- /*! formiojs v5.0.0-rc.42 | https://unpkg.com/formiojs@5.0.0-rc.42/LICENSE.txt */
15
+ /*! formiojs v5.0.0-rc.43 | https://unpkg.com/formiojs@5.0.0-rc.43/LICENSE.txt */
18
16
 
19
17
  /**
20
18
  * @license
@@ -693,12 +693,13 @@ class Webform extends NestedDataComponent_1.default {
693
693
  * @param {userId} - The user id where we need to restore the draft from.
694
694
  */
695
695
  restoreDraft(userId) {
696
- if (!this.formio) {
696
+ const formio = this.formio || this.options.formio;
697
+ if (!formio) {
697
698
  this.handleDraftError('restoreDraftInstanceError', null, true);
698
699
  return;
699
700
  }
700
701
  this.savingDraft = true;
701
- this.formio.loadSubmissions({
702
+ formio.loadSubmissions({
702
703
  params: {
703
704
  state: 'draft',
704
705
  owner: userId
@@ -997,10 +998,7 @@ class Webform extends NestedDataComponent_1.default {
997
998
  * @returns {*}
998
999
  */
999
1000
  /* eslint-disable no-unused-vars */
1000
- showErrors(errors, triggerEvent, onChange) {
1001
- if (!errors) {
1002
- return;
1003
- }
1001
+ showErrors(errors, triggerEvent) {
1004
1002
  this.loading = false;
1005
1003
  if (!Array.isArray(errors)) {
1006
1004
  errors = [errors];
@@ -1153,7 +1151,7 @@ class Webform extends NestedDataComponent_1.default {
1153
1151
  if (this.submitted) {
1154
1152
  // show server errors while they are not cleaned/fixed
1155
1153
  const nonComponentServerErrors = lodash_1.default.filter(this.serverErrors || [], err => !err.component && !err.path);
1156
- this.showErrors(nonComponentServerErrors.length ? nonComponentServerErrors : null);
1154
+ this.showErrors(nonComponentServerErrors.length ? nonComponentServerErrors : errors);
1157
1155
  }
1158
1156
  // See if we need to save the draft of the form.
1159
1157
  if (modified && this.options.saveDraft) {
@@ -2698,6 +2698,7 @@ class Component extends Element_1.default {
2698
2698
  component: this.component,
2699
2699
  data,
2700
2700
  row,
2701
+ value: this.validationValue,
2701
2702
  path: this.path || this.component.key,
2702
2703
  instance: this,
2703
2704
  scope: { errors: [] },
@@ -2965,6 +2966,11 @@ class Component extends Element_1.default {
2965
2966
  }
2966
2967
  shouldSkipValidation(data, row, flags = {}) {
2967
2968
  const { validateWhenHidden = false } = this.component || {};
2969
+ const forceValidOnHidden = (!this.visible || !this.checkCondition(row, data)) && !validateWhenHidden;
2970
+ if (forceValidOnHidden) {
2971
+ // If this component is forced valid when it is hidden, then we also need to reset the errors for this component.
2972
+ this._errors = [];
2973
+ }
2968
2974
  const rules = [
2969
2975
  // Do not validate if the flags say not too.
2970
2976
  () => flags.noValidate,
@@ -2975,9 +2981,7 @@ class Component extends Element_1.default {
2975
2981
  // Check to see if we are editing and if so, check component persistence.
2976
2982
  () => this.isValueHidden(),
2977
2983
  // Force valid if component is hidden.
2978
- () => !this.visible && !validateWhenHidden,
2979
- // Force valid if component is conditionally hidden.
2980
- () => !this.checkCondition(row, data) && !validateWhenHidden
2984
+ () => forceValidOnHidden
2981
2985
  ];
2982
2986
  return rules.some(pred => pred());
2983
2987
  }
@@ -189,7 +189,7 @@ class NestedArrayComponent extends NestedDataComponent_1.default {
189
189
  return super.getValueAsString(value, options);
190
190
  }
191
191
  getComponents(rowIndex) {
192
- if (rowIndex !== undefined) {
192
+ if (rowIndex !== undefined && rowIndex !== null) {
193
193
  if (!this.iteratableRows[rowIndex]) {
194
194
  return [];
195
195
  }
@@ -66,7 +66,7 @@ class NestedDataComponent extends NestedComponent_1.default {
66
66
  <tbody>
67
67
  `);
68
68
  const htmlTagRegExp = new RegExp('<(.*?)>');
69
- this.components.forEach((component) => {
69
+ this.everyComponent((component) => {
70
70
  if (component.isInputComponent && component.visible && !component.skipInEmail) {
71
71
  const componentValue = component.getView(component.dataValue, options);
72
72
  result += (`
@@ -1040,6 +1040,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
1040
1040
  }
1041
1041
  else {
1042
1042
  this.alert.clear();
1043
+ this.alert = null;
1043
1044
  }
1044
1045
  }
1045
1046
  }
@@ -143,6 +143,7 @@ class FormComponent extends Component_1.default {
143
143
  return this.subForm.getComponent(path, fn, originalPathStr);
144
144
  }
145
145
  }
146
+ /* eslint-disable max-statements */
146
147
  getSubOptions(options = {}) {
147
148
  options.events = this.createEmitter();
148
149
  // Make sure to not show the submit button in wizards in the nested forms.
@@ -200,12 +201,14 @@ class FormComponent extends Component_1.default {
200
201
  }
201
202
  if (this.options.saveDraft) {
202
203
  options.saveDraft = this.options.saveDraft;
204
+ options.formio = new Formio_1.Formio(this.formSrc);
203
205
  }
204
206
  if (this.options.saveDraftThrottle) {
205
207
  options.saveDraftThrottle = this.options.saveDraftThrottle;
206
208
  }
207
209
  return options;
208
210
  }
211
+ /* eslint-enable max-statements */
209
212
  render() {
210
213
  if (this.builderMode) {
211
214
  return super.render(this.component.label || 'Nested form');
@@ -403,10 +406,6 @@ class FormComponent extends Component_1.default {
403
406
  this.subForm.nosubmit = true;
404
407
  this.subForm.root = this.root;
405
408
  this.subForm.localRoot = this.isNestedWizard ? this.localRoot : this.subForm;
406
- if (this.parent) {
407
- this.subForm.draftEnabled = this.parent.draftEnabled;
408
- this.subForm.savingDraft = this.parent.savingDraft;
409
- }
410
409
  this.restoreValue();
411
410
  this.valueChanged = this.hasSetValue;
412
411
  this.onChange();
@@ -571,11 +570,15 @@ class FormComponent extends Component_1.default {
571
570
  * Submit the form before the whole form is triggered.
572
571
  */
573
572
  beforeSubmit() {
574
- var _a;
573
+ var _a, _b, _c;
575
574
  const submission = this.dataValue;
575
+ // Cancel triggered saveDraft
576
+ if (((_a = this.subForm) === null || _a === void 0 ? void 0 : _a.draftEnabled) && ((_b = this.subForm.triggerSaveDraft) === null || _b === void 0 ? void 0 : _b.cancel)) {
577
+ this.subForm.triggerSaveDraft.cancel();
578
+ }
576
579
  const isAlreadySubmitted = submission && submission._id && submission.form;
577
580
  // This submission has already been submitted, so just return the reference data.
578
- if (isAlreadySubmitted && !((_a = this.subForm) === null || _a === void 0 ? void 0 : _a.wizard)) {
581
+ if (isAlreadySubmitted && !((_c = this.subForm) === null || _c === void 0 ? void 0 : _c.wizard)) {
579
582
  this.dataValue = submission;
580
583
  return Promise.resolve(this.dataValue);
581
584
  }
@@ -338,7 +338,8 @@ class CalendarWidget extends InputWidget_1.default {
338
338
  this.input.setAttribute('aria-invalid', 'false');
339
339
  }
340
340
  }
341
- validationValue(value) {
341
+ get validationValue() {
342
+ const value = this.dataValue;
342
343
  if (typeof value === 'string') {
343
344
  return new Date(value);
344
345
  }
@@ -357,7 +358,7 @@ class CalendarWidget extends InputWidget_1.default {
357
358
  initFlatpickr(Flatpickr) {
358
359
  // Create a new flatpickr.
359
360
  this.calendar = new Flatpickr(this._input, Object.assign(Object.assign({}, this.settings), { disableMobile: true }));
360
- this.calendar.altInput.addEventListener('input', (event) => {
361
+ this.addEventListener(this.calendar.altInput, 'input', (event) => {
361
362
  if (this.settings.allowInput && this.settings.currentValue !== event.target.value) {
362
363
  this.settings.manualInputValue = event.target.value;
363
364
  this.settings.isManuallyOverriddenValue = true;
@@ -43,8 +43,8 @@ class InputWidget extends Element_1.default {
43
43
  getValueAsString(value) {
44
44
  return value;
45
45
  }
46
- validationValue(value) {
47
- return value;
46
+ get validationValue() {
47
+ return this.dataValue;
48
48
  }
49
49
  addPrefix() {
50
50
  return null;
@@ -693,12 +693,13 @@ export default class Webform extends NestedDataComponent {
693
693
  * @param {userId} - The user id where we need to restore the draft from.
694
694
  */
695
695
  restoreDraft(userId) {
696
- if (!this.formio) {
696
+ const formio = this.formio || this.options.formio;
697
+ if (!formio) {
697
698
  this.handleDraftError('restoreDraftInstanceError', null, true);
698
699
  return;
699
700
  }
700
701
  this.savingDraft = true;
701
- this.formio.loadSubmissions({
702
+ formio.loadSubmissions({
702
703
  params: {
703
704
  state: 'draft',
704
705
  owner: userId
@@ -997,10 +998,7 @@ export default class Webform extends NestedDataComponent {
997
998
  * @returns {*}
998
999
  */
999
1000
  /* eslint-disable no-unused-vars */
1000
- showErrors(errors, triggerEvent, onChange) {
1001
- if (!errors) {
1002
- return;
1003
- }
1001
+ showErrors(errors, triggerEvent) {
1004
1002
  this.loading = false;
1005
1003
  if (!Array.isArray(errors)) {
1006
1004
  errors = [errors];
@@ -1151,7 +1149,7 @@ export default class Webform extends NestedDataComponent {
1151
1149
  if (this.submitted) {
1152
1150
  // show server errors while they are not cleaned/fixed
1153
1151
  const nonComponentServerErrors = _.filter(this.serverErrors || [], err => !err.component && !err.path);
1154
- this.showErrors(nonComponentServerErrors.length ? nonComponentServerErrors : null);
1152
+ this.showErrors(nonComponentServerErrors.length ? nonComponentServerErrors : errors);
1155
1153
  }
1156
1154
  // See if we need to save the draft of the form.
1157
1155
  if (modified && this.options.saveDraft) {
@@ -2665,6 +2665,7 @@ export default class Component extends Element {
2665
2665
  component: this.component,
2666
2666
  data,
2667
2667
  row,
2668
+ value: this.validationValue,
2668
2669
  path: this.path || this.component.key,
2669
2670
  instance: this,
2670
2671
  scope: { errors: [] },
@@ -2930,6 +2931,11 @@ export default class Component extends Element {
2930
2931
  }
2931
2932
  shouldSkipValidation(data, row, flags = {}) {
2932
2933
  const { validateWhenHidden = false } = this.component || {};
2934
+ const forceValidOnHidden = (!this.visible || !this.checkCondition(row, data)) && !validateWhenHidden;
2935
+ if (forceValidOnHidden) {
2936
+ // If this component is forced valid when it is hidden, then we also need to reset the errors for this component.
2937
+ this._errors = [];
2938
+ }
2933
2939
  const rules = [
2934
2940
  // Do not validate if the flags say not too.
2935
2941
  () => flags.noValidate,
@@ -2940,9 +2946,7 @@ export default class Component extends Element {
2940
2946
  // Check to see if we are editing and if so, check component persistence.
2941
2947
  () => this.isValueHidden(),
2942
2948
  // Force valid if component is hidden.
2943
- () => !this.visible && !validateWhenHidden,
2944
- // Force valid if component is conditionally hidden.
2945
- () => !this.checkCondition(row, data) && !validateWhenHidden
2949
+ () => forceValidOnHidden
2946
2950
  ];
2947
2951
  return rules.some(pred => pred());
2948
2952
  }
@@ -184,7 +184,7 @@ export default class NestedArrayComponent extends NestedDataComponent {
184
184
  return super.getValueAsString(value, options);
185
185
  }
186
186
  getComponents(rowIndex) {
187
- if (rowIndex !== undefined) {
187
+ if (rowIndex !== undefined && rowIndex !== null) {
188
188
  if (!this.iteratableRows[rowIndex]) {
189
189
  return [];
190
190
  }
@@ -65,7 +65,7 @@ export default class NestedDataComponent extends NestedComponent {
65
65
  <tbody>
66
66
  `);
67
67
  const htmlTagRegExp = new RegExp('<(.*?)>');
68
- this.components.forEach((component) => {
68
+ this.everyComponent((component) => {
69
69
  if (component.isInputComponent && component.visible && !component.skipInEmail) {
70
70
  const componentValue = component.getView(component.dataValue, options);
71
71
  result += (`
@@ -1029,6 +1029,7 @@ export default class EditGridComponent extends NestedArrayComponent {
1029
1029
  }
1030
1030
  else {
1031
1031
  this.alert.clear();
1032
+ this.alert = null;
1032
1033
  }
1033
1034
  }
1034
1035
  }
@@ -137,6 +137,7 @@ export default class FormComponent extends Component {
137
137
  return this.subForm.getComponent(path, fn, originalPathStr);
138
138
  }
139
139
  }
140
+ /* eslint-disable max-statements */
140
141
  getSubOptions(options = {}) {
141
142
  options.events = this.createEmitter();
142
143
  // Make sure to not show the submit button in wizards in the nested forms.
@@ -194,12 +195,14 @@ export default class FormComponent extends Component {
194
195
  }
195
196
  if (this.options.saveDraft) {
196
197
  options.saveDraft = this.options.saveDraft;
198
+ options.formio = new Formio(this.formSrc);
197
199
  }
198
200
  if (this.options.saveDraftThrottle) {
199
201
  options.saveDraftThrottle = this.options.saveDraftThrottle;
200
202
  }
201
203
  return options;
202
204
  }
205
+ /* eslint-enable max-statements */
203
206
  render() {
204
207
  if (this.builderMode) {
205
208
  return super.render(this.component.label || 'Nested form');
@@ -399,10 +402,6 @@ export default class FormComponent extends Component {
399
402
  this.subForm.nosubmit = true;
400
403
  this.subForm.root = this.root;
401
404
  this.subForm.localRoot = this.isNestedWizard ? this.localRoot : this.subForm;
402
- if (this.parent) {
403
- this.subForm.draftEnabled = this.parent.draftEnabled;
404
- this.subForm.savingDraft = this.parent.savingDraft;
405
- }
406
405
  this.restoreValue();
407
406
  this.valueChanged = this.hasSetValue;
408
407
  this.onChange();
@@ -566,6 +565,10 @@ export default class FormComponent extends Component {
566
565
  */
567
566
  beforeSubmit() {
568
567
  const submission = this.dataValue;
568
+ // Cancel triggered saveDraft
569
+ if (this.subForm?.draftEnabled && this.subForm.triggerSaveDraft?.cancel) {
570
+ this.subForm.triggerSaveDraft.cancel();
571
+ }
569
572
  const isAlreadySubmitted = submission && submission._id && submission.form;
570
573
  // This submission has already been submitted, so just return the reference data.
571
574
  if (isAlreadySubmitted && !this.subForm?.wizard) {
@@ -330,7 +330,8 @@ export default class CalendarWidget extends InputWidget {
330
330
  this.input.setAttribute('aria-invalid', 'false');
331
331
  }
332
332
  }
333
- validationValue(value) {
333
+ get validationValue() {
334
+ const value = this.dataValue;
334
335
  if (typeof value === 'string') {
335
336
  return new Date(value);
336
337
  }
@@ -348,7 +349,7 @@ export default class CalendarWidget extends InputWidget {
348
349
  initFlatpickr(Flatpickr) {
349
350
  // Create a new flatpickr.
350
351
  this.calendar = new Flatpickr(this._input, { ...this.settings, disableMobile: true });
351
- this.calendar.altInput.addEventListener('input', (event) => {
352
+ this.addEventListener(this.calendar.altInput, 'input', (event) => {
352
353
  if (this.settings.allowInput && this.settings.currentValue !== event.target.value) {
353
354
  this.settings.manualInputValue = event.target.value;
354
355
  this.settings.isManuallyOverriddenValue = true;
@@ -38,8 +38,8 @@ export default class InputWidget extends Element {
38
38
  getValueAsString(value) {
39
39
  return value;
40
40
  }
41
- validationValue(value) {
42
- return value;
41
+ get validationValue() {
42
+ return this.dataValue;
43
43
  }
44
44
  addPrefix() {
45
45
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.0.0-rc.42",
3
+ "version": "5.0.0-rc.43",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {
@@ -86,7 +86,7 @@
86
86
  "dependencies": {
87
87
  "@formio/bootstrap": "^3.0.0-rc.22",
88
88
  "@formio/choices.js": "^10.2.1",
89
- "@formio/core": "^2.0.0-tt.dev-882e7ea",
89
+ "@formio/core": "^2.1.0-dev.tt.2",
90
90
  "@formio/text-mask-addons": "^3.8.0-formio.2",
91
91
  "@formio/vanilla-text-mask": "^5.1.1-formio.1",
92
92
  "abortcontroller-polyfill": "^1.7.5",
@@ -95,10 +95,10 @@
95
95
  "browser-cookies": "^1.2.0",
96
96
  "browser-md5-file": "^1.1.1",
97
97
  "compare-versions": "^6.0.0-rc.2",
98
- "core-js": "^3.36.0",
98
+ "core-js": "^3.37.0",
99
99
  "dialog-polyfill": "^0.5.6",
100
100
  "dom-autoscroller": "^2.3.4",
101
- "dompurify": "^3.0.9",
101
+ "dompurify": "^3.1.0",
102
102
  "downloadjs": "^1.4.7",
103
103
  "dragula": "^3.7.3",
104
104
  "eventemitter3": "^5.0.1",
@@ -122,9 +122,9 @@
122
122
  "vanilla-picker": "^2.12.3"
123
123
  },
124
124
  "devDependencies": {
125
- "@typescript-eslint/eslint-plugin": "^7.3.0",
126
- "@typescript-eslint/parser": "^7.3.0",
127
- "ace-builds": "1.32.9",
125
+ "@typescript-eslint/eslint-plugin": "^7.6.0",
126
+ "@typescript-eslint/parser": "^7.6.0",
127
+ "ace-builds": "1.33.0",
128
128
  "async-limiter": "^2.0.0",
129
129
  "bootstrap-icons": "^1.10.5",
130
130
  "bootswatch": "^5.3.3",
@@ -154,7 +154,7 @@
154
154
  "gulp-sync": "^0.1.4",
155
155
  "gulp-watch": "^5.0.1",
156
156
  "hoek": "^6.1.3",
157
- "jsdom": "^24.0.0",
157
+ "jsdom": "22.1.0",
158
158
  "jsdom-global": "^3.0.2",
159
159
  "karma": "^6.4.3",
160
160
  "karma-chrome-launcher": "^3.2.0",
@@ -170,15 +170,15 @@
170
170
  "pretty": "^2.0.0",
171
171
  "pygments-css": "^1.0.0",
172
172
  "raw-loader": "^4.0.2",
173
- "sass": "^1.72.0",
173
+ "sass": "^1.74.1",
174
174
  "shortcut-buttons-flatpickr": "^0.4.0",
175
175
  "sinon": "^17.0.1",
176
176
  "string-replace-loader": "^3.1.0",
177
177
  "ts-loader": "^9.4.4",
178
178
  "ts-node": "^10.9.1",
179
- "typescript": "5.3.3",
179
+ "typescript": "5.3.2",
180
180
  "webpack": "^5.90.3",
181
- "webpack-bundle-analyzer": "^4.9.0",
181
+ "webpack-bundle-analyzer": "^4.10.2",
182
182
  "webpack-cli": "^5.1.1",
183
183
  "webpack-node-externals": "^3.0.0",
184
184
  "webpack-stream": "^7.0.0",