@formio/js 5.0.0-bb.dev.3 → 5.0.0-bb.dev.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 (54) 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 +12 -12
  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 +12 -12
  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 +1 -1
  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/Form.js +0 -15
  15. package/lib/cjs/components/_classes/component/Component.js +10 -4
  16. package/lib/cjs/components/_classes/component/editForm/Component.edit.validation.js +8 -0
  17. package/lib/cjs/components/_classes/nested/NestedComponent.js +2 -2
  18. package/lib/cjs/components/datagrid/DataGrid.js +2 -1
  19. package/lib/cjs/components/datagrid/fixtures/comp-with-allow-calculate-override.js +1 -1
  20. package/lib/cjs/components/datagrid/fixtures/index.d.ts +2 -1
  21. package/lib/cjs/components/datagrid/fixtures/index.js +3 -1
  22. package/lib/cjs/components/datagrid/fixtures/two-comp-with-allow-calculate-override.d.ts +53 -0
  23. package/lib/cjs/components/datagrid/fixtures/two-comp-with-allow-calculate-override.js +104 -0
  24. package/lib/cjs/components/editgrid/EditGrid.js +7 -4
  25. package/lib/cjs/components/editgrid/fixtures/formsWithEditGridAndConditions.d.ts +910 -0
  26. package/lib/cjs/components/editgrid/fixtures/formsWithEditGridAndConditions.js +923 -0
  27. package/lib/cjs/components/html/HTML.d.ts +1 -0
  28. package/lib/cjs/components/html/HTML.js +9 -0
  29. package/lib/cjs/components/recaptcha/ReCaptcha.js +3 -3
  30. package/lib/cjs/formio.form.js +14 -0
  31. package/lib/cjs/translations/en.d.ts +2 -0
  32. package/lib/cjs/translations/en.js +2 -0
  33. package/lib/cjs/validator/Validator.js +1 -1
  34. package/lib/mjs/Form.js +0 -15
  35. package/lib/mjs/components/_classes/component/Component.js +10 -4
  36. package/lib/mjs/components/_classes/component/editForm/Component.edit.validation.js +8 -0
  37. package/lib/mjs/components/_classes/nested/NestedComponent.js +2 -2
  38. package/lib/mjs/components/datagrid/DataGrid.js +2 -1
  39. package/lib/mjs/components/datagrid/fixtures/comp-with-allow-calculate-override.js +1 -1
  40. package/lib/mjs/components/datagrid/fixtures/index.d.ts +2 -1
  41. package/lib/mjs/components/datagrid/fixtures/index.js +2 -1
  42. package/lib/mjs/components/datagrid/fixtures/two-comp-with-allow-calculate-override.d.ts +53 -0
  43. package/lib/mjs/components/datagrid/fixtures/two-comp-with-allow-calculate-override.js +102 -0
  44. package/lib/mjs/components/editgrid/EditGrid.js +7 -4
  45. package/lib/mjs/components/editgrid/fixtures/formsWithEditGridAndConditions.d.ts +910 -0
  46. package/lib/mjs/components/editgrid/fixtures/formsWithEditGridAndConditions.js +921 -0
  47. package/lib/mjs/components/html/HTML.d.ts +1 -0
  48. package/lib/mjs/components/html/HTML.js +8 -0
  49. package/lib/mjs/components/recaptcha/ReCaptcha.js +3 -3
  50. package/lib/mjs/formio.form.js +14 -0
  51. package/lib/mjs/translations/en.d.ts +2 -0
  52. package/lib/mjs/translations/en.js +2 -0
  53. package/lib/mjs/validator/Validator.js +1 -1
  54. package/package.json +2 -2
@@ -14,5 +14,6 @@ export default class HTMLComponent extends Component {
14
14
  checkRefreshOn(changed: any): void;
15
15
  renderContent(): any;
16
16
  render(): any;
17
+ get dataReady(): any;
17
18
  }
18
19
  import Component from '../_classes/component/Component';
@@ -85,8 +85,17 @@ class HTMLComponent extends Component_1.default {
85
85
  render() {
86
86
  return super.render(this.renderContent());
87
87
  }
88
+ get dataReady() {
89
+ var _a;
90
+ return ((_a = this.root) === null || _a === void 0 ? void 0 : _a.submissionReady) || Promise.resolve();
91
+ }
88
92
  attach(element) {
89
93
  this.loadRefs(element, { html: 'single' });
94
+ this.dataReady.then(() => {
95
+ if (this.element) {
96
+ this.setContent(this.elemet, this.content);
97
+ }
98
+ });
90
99
  return super.attach(element);
91
100
  }
92
101
  }
@@ -123,17 +123,17 @@ class ReCaptchaComponent extends Component_1.default {
123
123
  }
124
124
  const componentData = row[this.component.key];
125
125
  if (!componentData || !componentData.token) {
126
- this.setCustomValidity('ReCAPTCHA: Token is not specified in submission');
126
+ this.setCustomValidity(this.t('reCaptchaTokenNotSpecifiedError'));
127
127
  return Promise.resolve(false);
128
128
  }
129
129
  if (!componentData.success) {
130
- this.setCustomValidity('ReCAPTCHA: Token validation error');
130
+ this.setCustomValidity(this.t('reCaptchaTokenValidationError'));
131
131
  return Promise.resolve(false);
132
132
  }
133
133
  return this.hook('validateReCaptcha', componentData.token, () => Promise.resolve(true))
134
134
  .then((success) => success)
135
135
  .catch((err) => {
136
- this.setCustomValidity(err.message || err);
136
+ this.setCustomValidity(this.t(err.message || err));
137
137
  return false;
138
138
  });
139
139
  }
@@ -167,3 +167,17 @@ exports.useModule = useModule;
167
167
  * Formio.plugins([plugin1, plugin2, etc], options);
168
168
  */
169
169
  Formio_1.Formio.use = useModule();
170
+ // Allow simple embedding.
171
+ Formio_1.Formio.embedForm = (embed) => Form_1.default.embed(embed);
172
+ /**
173
+ * Factory that creates a new form based on the form parameters.
174
+ *
175
+ * @param element {HMTLElement} - The HTML Element to add this form to.
176
+ * @param form {string|Object} - The src of the form, or a form object.
177
+ * @param options {Object} - The options to create this form.
178
+ *
179
+ * @return {Promise} - When the form is instance is ready.
180
+ */
181
+ Formio_1.Formio.createForm = (...args) => {
182
+ return (new Form_1.default(...args)).ready;
183
+ };
@@ -62,5 +62,7 @@ declare namespace _default {
62
62
  const previousButtonAriaLabel: string;
63
63
  const nextButtonAriaLabel: string;
64
64
  const submitButtonAriaLabel: string;
65
+ const reCaptchaTokenValidationError: string;
66
+ const reCaptchaTokenNotSpecifiedError: string;
65
67
  }
66
68
  export default _default;
@@ -64,4 +64,6 @@ exports.default = {
64
64
  previousButtonAriaLabel: 'Previous button. Click to go back to the previous tab',
65
65
  nextButtonAriaLabel: 'Next button. Click to go to the next tab',
66
66
  submitButtonAriaLabel: 'Submit Form button. Click to submit the form',
67
+ reCaptchaTokenValidationError: 'ReCAPTCHA: Token validation error',
68
+ reCaptchaTokenNotSpecifiedError: 'ReCAPTCHA: Token is not specified in submission',
67
69
  };
@@ -860,7 +860,7 @@ class ValidationChecker {
860
860
  }
861
861
  validate(component, validatorName, value, data, index, row, async, conditionallyVisible, validationObj) {
862
862
  // Skip validation for conditionally hidden components
863
- if (!conditionallyVisible) {
863
+ if (!conditionallyVisible && !lodash_1.default.get(component.component, 'validateWhenHidden', false)) {
864
864
  return false;
865
865
  }
866
866
  const validator = this.validators[validatorName];
package/lib/mjs/Form.js CHANGED
@@ -335,18 +335,3 @@ export default class Form extends Element {
335
335
  delete this.ready;
336
336
  }
337
337
  }
338
- // Allow simple embedding.
339
- Formio.embedForm = (embed) => Form.embed(embed);
340
- /**
341
- * Factory that creates a new form based on the form parameters.
342
- *
343
- * @param element {HMTLElement} - The HTML Element to add this form to.
344
- * @param form {string|Object} - The src of the form, or a form object.
345
- * @param options {Object} - The options to create this form.
346
- *
347
- * @return {Promise} - When the form is instance is ready.
348
- */
349
- Formio.createForm = (...args) => {
350
- return (new Form(...args)).ready;
351
- };
352
- Formio.Form = Form;
@@ -1811,6 +1811,10 @@ export default class Component extends Element {
1811
1811
  this.setElementInvalid(this.performInputMapping(element), false);
1812
1812
  });
1813
1813
  this.setInputWidgetErrorClasses(elements, hasErrors);
1814
+ // do not set error classes for hidden components
1815
+ if (!this.visible) {
1816
+ return;
1817
+ }
1814
1818
  if (hasErrors) {
1815
1819
  // Add error classes
1816
1820
  elements.forEach((input) => {
@@ -2428,8 +2432,8 @@ export default class Component extends Element {
2428
2432
  }
2429
2433
  /* eslint-disable max-statements */
2430
2434
  calculateComponentValue(data, flags, row) {
2431
- // Skip value calculation for the component if we don't have entire form data set
2432
- if (_.isUndefined(_.get(this, 'root.data'))) {
2435
+ // Skip value calculation for the component if we don't have entire form data set or in builder mode
2436
+ if (this.builderMode || _.isUndefined(_.get(this, 'root.data'))) {
2433
2437
  return false;
2434
2438
  }
2435
2439
  // If no calculated value or
@@ -2487,6 +2491,7 @@ export default class Component extends Element {
2487
2491
  }
2488
2492
  // Check to ensure that the calculated value is different than the previously calculated value.
2489
2493
  if (previousCalculatedValue && previousChanged && !calculationChanged) {
2494
+ this.calculatedValue = null;
2490
2495
  return false;
2491
2496
  }
2492
2497
  if (flags.isReordered || !calculationChanged) {
@@ -2842,6 +2847,7 @@ export default class Component extends Element {
2842
2847
  return (this.component.protected || !this.component.persistent || (this.component.persistent === 'client-only'));
2843
2848
  }
2844
2849
  shouldSkipValidation(data, dirty, row) {
2850
+ const { validateWhenHidden = false } = this.component || {};
2845
2851
  const rules = [
2846
2852
  // Force valid if component is read-only
2847
2853
  () => this.options.readOnly,
@@ -2850,9 +2856,9 @@ export default class Component extends Element {
2850
2856
  // Check to see if we are editing and if so, check component persistence.
2851
2857
  () => this.isValueHidden(),
2852
2858
  // Force valid if component is hidden.
2853
- () => !this.visible,
2859
+ () => !this.visible && !validateWhenHidden,
2854
2860
  // Force valid if component is conditionally hidden.
2855
- () => !this.checkCondition(row, data)
2861
+ () => !this.checkCondition(row, data) && !validateWhenHidden
2856
2862
  ];
2857
2863
  return rules.some(pred => pred());
2858
2864
  }
@@ -18,6 +18,14 @@ export default [
18
18
  key: 'unique',
19
19
  input: true
20
20
  },
21
+ {
22
+ weight: 100,
23
+ type: 'checkbox',
24
+ label: 'Validate When Hidden',
25
+ tooltip: 'Validates the component when it is hidden/conditionally hidden. Vaildation errors are displayed in the error alert on the form submission.',
26
+ key: 'validateWhenHidden',
27
+ input: true
28
+ },
21
29
  {
22
30
  weight: 0,
23
31
  type: 'select',
@@ -526,8 +526,8 @@ export default class NestedComponent extends Field {
526
526
  row = row || this.data;
527
527
  components = components && _.isArray(components) ? components : this.getComponents();
528
528
  const isValid = components.reduce((valid, comp) => {
529
- return comp.checkData(data, flags, row) && valid;
530
- }, super.checkData(data, flags, row));
529
+ return comp.checkData(data, { ...flags }, row) && valid;
530
+ }, super.checkData(data, { ...flags }, row));
531
531
  this.checkModal(isValid, this.isDirty);
532
532
  return isValid;
533
533
  }
@@ -583,7 +583,8 @@ export default class DataGridComponent extends NestedArrayComponent {
583
583
  const isSettingSubmission = flags.fromSubmission && !_.isEqual(value, this.emptyValue);
584
584
  const changed = this.hasChanged(value, this.dataValue);
585
585
  this.dataValue = value;
586
- if (this.initRows || isSettingSubmission) {
586
+ if (this.initRows || isSettingSubmission ||
587
+ (Array.isArray(this.dataValue) && this.dataValue.length !== this.rows.length)) {
587
588
  if (!this.createRows() && changed) {
588
589
  this.redraw();
589
590
  }
@@ -40,7 +40,7 @@ export default {
40
40
  lastName: ''
41
41
  }
42
42
  ],
43
- calculateValue: "var temp = [\n {'firstName': 'initial 1','lastName': 'initial 2'},\n {'firstName': 'initial 1b','lastName': 'initial 2b'},\n ];\n if(data.select === 'a')\n {\n temp = [{'firstName': 'A f 1','lastName': 'A l 1'}];\n } else if(data.select === 'b') { \n temp = [{'firstName': 'B f 1','lastName': 'B l 1'} \n ,{'firstName': 'B f 2','lastName': 'B l 2'}];\n } else if(data.select === 'c') { \n temp = [{'firstName': 'C f 1','lastName': 'C l 1'}];\n }\n value = temp;",
43
+ calculateValue: "var temp = instance.defaultValue;\n if(data.select === 'a')\n {\n temp = [{'firstName': 'A f 1','lastName': 'A l 1'}];\n } else if(data.select === 'b') { \n temp = [{'firstName': 'B f 1','lastName': 'B l 1'} \n ,{'firstName': 'B f 2','lastName': 'B l 2'}];\n } else if(data.select === 'c') { \n temp = [{'firstName': 'C f 1','lastName': 'C l 1'}];\n }\n value = temp;",
44
44
  allowCalculateOverride: true,
45
45
  key: 'dataGrid',
46
46
  type: 'datagrid',
@@ -13,4 +13,5 @@ import withLogic from './comp-with-logic';
13
13
  import withRowGroupsAndDefValue from './comp-row-groups-with-def-value';
14
14
  import modalWithRequiredFields from './comp-modal-with-required-fields';
15
15
  import withAllowCalculateOverride from './comp-with-allow-calculate-override';
16
- export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, withCollapsibleRowGroups, withConditionalFieldsAndValidations, withDefValue, withLogic, withRowGroupsAndDefValue, modalWithRequiredFields, withAllowCalculateOverride };
16
+ import twoWithAllowCalculatedOverride from './two-comp-with-allow-calculate-override';
17
+ export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, withCollapsibleRowGroups, withConditionalFieldsAndValidations, withDefValue, withLogic, withRowGroupsAndDefValue, modalWithRequiredFields, withAllowCalculateOverride, twoWithAllowCalculatedOverride };
@@ -13,4 +13,5 @@ import withConditionalFieldsAndValidations from './comp-with-conditional-compone
13
13
  import withLogic from './comp-with-logic';
14
14
  import withCollapsibleRowGroups from './comp-with-collapsible-groups';
15
15
  import withAllowCalculateOverride from './comp-with-allow-calculate-override';
16
- export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, withCollapsibleRowGroups, withConditionalFieldsAndValidations, withDefValue, withLogic, withRowGroupsAndDefValue, modalWithRequiredFields, withAllowCalculateOverride };
16
+ import twoWithAllowCalculatedOverride from './two-comp-with-allow-calculate-override';
17
+ export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, withCollapsibleRowGroups, withConditionalFieldsAndValidations, withDefValue, withLogic, withRowGroupsAndDefValue, modalWithRequiredFields, withAllowCalculateOverride, twoWithAllowCalculatedOverride };
@@ -0,0 +1,53 @@
1
+ declare namespace _default {
2
+ const type: string;
3
+ const display: string;
4
+ const components: ({
5
+ label: string;
6
+ widget: string;
7
+ tableView: boolean;
8
+ data: {
9
+ values: {
10
+ label: string;
11
+ value: string;
12
+ }[];
13
+ };
14
+ key: string;
15
+ type: string;
16
+ input: boolean;
17
+ reorder?: undefined;
18
+ addAnotherPosition?: undefined;
19
+ layoutFixed?: undefined;
20
+ enableRowGroups?: undefined;
21
+ initEmpty?: undefined;
22
+ defaultValue?: undefined;
23
+ allowCalculateOverride?: undefined;
24
+ components?: undefined;
25
+ } | {
26
+ label: string;
27
+ reorder: boolean;
28
+ addAnotherPosition: string;
29
+ layoutFixed: boolean;
30
+ enableRowGroups: boolean;
31
+ initEmpty: boolean;
32
+ tableView: boolean;
33
+ defaultValue: {
34
+ firstName: string;
35
+ lastName: string;
36
+ }[];
37
+ calculateValue: string;
38
+ allowCalculateOverride: boolean;
39
+ key: string;
40
+ type: string;
41
+ input: boolean;
42
+ components: {
43
+ label: string;
44
+ tableView: boolean;
45
+ key: string;
46
+ type: string;
47
+ input: boolean;
48
+ }[];
49
+ widget?: undefined;
50
+ data?: undefined;
51
+ })[];
52
+ }
53
+ export default _default;
@@ -0,0 +1,102 @@
1
+ export default {
2
+ type: 'form',
3
+ display: 'form',
4
+ components: [
5
+ {
6
+ label: 'Select',
7
+ widget: 'choicesjs',
8
+ tableView: true,
9
+ data: {
10
+ values: [
11
+ {
12
+ label: 'a',
13
+ value: 'a'
14
+ },
15
+ {
16
+ label: 'b',
17
+ value: 'b'
18
+ },
19
+ {
20
+ label: 'c',
21
+ value: 'c'
22
+ }
23
+ ]
24
+ },
25
+ key: 'select',
26
+ type: 'select',
27
+ input: true
28
+ },
29
+ {
30
+ label: 'Data Grid',
31
+ reorder: false,
32
+ addAnotherPosition: 'bottom',
33
+ layoutFixed: false,
34
+ enableRowGroups: false,
35
+ initEmpty: false,
36
+ tableView: false,
37
+ defaultValue: [
38
+ {
39
+ firstName: '',
40
+ lastName: ''
41
+ }
42
+ ],
43
+ calculateValue: "var temp = instance.defaultValue;\n if(data.select === 'a')\n {\n temp = [{'firstName': 'A f 1','lastName': 'A l 1'}];\n } else if(data.select === 'b') { \n temp = [{'firstName': 'B f 1','lastName': 'B l 1'} \n ,{'firstName': 'B f 2','lastName': 'B l 2'}];\n } else if(data.select === 'c') { \n temp = [{'firstName': 'C f 1','lastName': 'C l 1'}];\n }\n value = temp;",
44
+ allowCalculateOverride: true,
45
+ key: 'dataGrid',
46
+ type: 'datagrid',
47
+ input: true,
48
+ components: [
49
+ {
50
+ label: 'First Name',
51
+ tableView: true,
52
+ key: 'firstName',
53
+ type: 'textfield',
54
+ input: true
55
+ },
56
+ {
57
+ label: 'Last Name',
58
+ tableView: true,
59
+ key: 'lastName',
60
+ type: 'textfield',
61
+ input: true
62
+ }
63
+ ]
64
+ },
65
+ {
66
+ label: 'Data Grid 2',
67
+ reorder: false,
68
+ addAnotherPosition: 'bottom',
69
+ layoutFixed: false,
70
+ enableRowGroups: false,
71
+ initEmpty: false,
72
+ tableView: false,
73
+ defaultValue: [
74
+ {
75
+ firstName: '',
76
+ lastName: ''
77
+ }
78
+ ],
79
+ calculateValue: "var temp = instance.defaultValue;\n if(data.select === 'a')\n {\n temp = [{'firstName': 'A f 1','lastName': 'A l 1'}];\n } else if(data.select === 'b') { \n temp = [{'firstName': 'B f 1','lastName': 'B l 1'} \n ,{'firstName': 'B f 2','lastName': 'B l 2'}];\n } else if(data.select === 'c') { \n temp = [{'firstName': 'C f 1','lastName': 'C l 1'}];\n }\n value = temp;",
80
+ allowCalculateOverride: true,
81
+ key: 'dataGrid2',
82
+ type: 'datagrid',
83
+ input: true,
84
+ components: [
85
+ {
86
+ label: 'First Name',
87
+ tableView: true,
88
+ key: 'firstName',
89
+ type: 'textfield',
90
+ input: true
91
+ },
92
+ {
93
+ label: 'Last Name',
94
+ tableView: true,
95
+ key: 'lastName',
96
+ type: 'textfield',
97
+ input: true
98
+ }
99
+ ]
100
+ }
101
+ ]
102
+ };
@@ -1064,7 +1064,7 @@ export default class EditGridComponent extends NestedArrayComponent {
1064
1064
  }
1065
1065
  return false;
1066
1066
  }
1067
- else if (rowsEditing && this.saveEditMode) {
1067
+ else if (rowsEditing && this.saveEditMode && !this.component.openWhenEmpty) {
1068
1068
  this.setCustomValidity(this.t(this.errorMessage('unsavedRowsError')), dirty);
1069
1069
  return false;
1070
1070
  }
@@ -1079,7 +1079,7 @@ export default class EditGridComponent extends NestedArrayComponent {
1079
1079
  return superValid;
1080
1080
  }
1081
1081
  changeState(changed, flags) {
1082
- if (changed || (flags.resetValue && this.component.modalEdit)) {
1082
+ if (this.visible && (changed || (flags.resetValue && this.component.modalEdit))) {
1083
1083
  this.rebuild();
1084
1084
  }
1085
1085
  else {
@@ -1100,7 +1100,7 @@ export default class EditGridComponent extends NestedArrayComponent {
1100
1100
  }
1101
1101
  const changed = this.hasChanged(value, this.dataValue);
1102
1102
  flags.noValidate = !changed;
1103
- if (this.parent && !(this.options.server && !this.parent.parentVisible)) {
1103
+ if (this.parent && !this.options.server) {
1104
1104
  this.parent.checkComponentConditions();
1105
1105
  }
1106
1106
  this.dataValue = value;
@@ -1133,7 +1133,10 @@ export default class EditGridComponent extends NestedArrayComponent {
1133
1133
  this.editRows = this.editRows.slice(0, dataLength);
1134
1134
  this.openWhenEmpty();
1135
1135
  this.updateOnChange(flags, changed);
1136
- this.checkData();
1136
+ // do not call checkData with server option, it is called when change is triggered in updateOnChange
1137
+ if (!this.options.server) {
1138
+ this.checkData();
1139
+ }
1137
1140
  this.changeState(changed, flags);
1138
1141
  return changed;
1139
1142
  }