@formio/js 5.0.0-dev.5875.f359435 → 5.0.0-dev.5878.d6b667a

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.
@@ -1533,7 +1533,7 @@ class Webform extends NestedDataComponent_1.default {
1533
1533
  return;
1534
1534
  }
1535
1535
  const captchaComponent = [];
1536
- (0, formUtils_1.eachComponentData)(this.components, {}, (component) => {
1536
+ (0, formUtils_1.eachComponent)(this.components, (component) => {
1537
1537
  if (/^(re)?captcha$/.test(component.type) && component.component.eventType === 'formLoad') {
1538
1538
  captchaComponent.push(component);
1539
1539
  }
package/lib/cjs/Wizard.js CHANGED
@@ -916,7 +916,7 @@ class Wizard extends Webform_1.default {
916
916
  const components = !currentPageOnly || this.isLastPage()
917
917
  ? this.getComponents()
918
918
  : this.currentPage.components;
919
- return components.reduce((check, comp) => comp.checkValidity(data, dirty, row, childErrors) && check, true);
919
+ return components.reduce((check, comp) => comp.checkValidity(data, dirty, row, currentPageOnly, childErrors) && check, true);
920
920
  }
921
921
  get errors() {
922
922
  if (!this.isLastPage()) {
@@ -11,6 +11,7 @@ export default class DayComponent extends Field {
11
11
  operators: string[];
12
12
  };
13
13
  static savedValueTypes(schema: any): string[];
14
+ static oldEmptyValue: string;
14
15
  static get serverConditionSettings(): {
15
16
  operators: string[];
16
17
  };
@@ -104,6 +104,12 @@ class DayComponent extends Field_1.default {
104
104
  info.changeEvent = 'input';
105
105
  return info;
106
106
  }
107
+ isEmpty(value = this.dataValue) {
108
+ if (value === DayComponent.oldEmptyValue) {
109
+ return true;
110
+ }
111
+ return super.isEmpty(value);
112
+ }
107
113
  inputDefinition(name) {
108
114
  let min, max;
109
115
  if (name === 'day') {
@@ -337,6 +343,10 @@ class DayComponent extends Field_1.default {
337
343
  }
338
344
  }
339
345
  normalizeValue(value) {
346
+ // Adjust the value from old to new format
347
+ if (value === DayComponent.oldEmptyValue) {
348
+ value = '';
349
+ }
340
350
  if (!value || this.valueMask.test(value)) {
341
351
  return value;
342
352
  }
@@ -643,4 +653,6 @@ class DayComponent extends Field_1.default {
643
653
  return validationFormat;
644
654
  }
645
655
  }
656
+ // Empty value used before 9.3.x
657
+ DayComponent.oldEmptyValue = '00/00/0000';
646
658
  exports.default = DayComponent;
@@ -84,6 +84,7 @@ class NumberComponent extends Input_1.default {
84
84
  decimalLimit: lodash_1.default.get(this.component, 'decimalLimit', this.decimalLimit),
85
85
  allowNegative: lodash_1.default.get(this.component, 'allowNegative', true),
86
86
  allowDecimal: this.isDecimalAllowed(),
87
+ allowScientificNotation: lodash_1.default.get(this.component, 'allowScientificNotation', false),
87
88
  });
88
89
  }
89
90
  get defaultSchema() {
@@ -116,6 +117,10 @@ class NumberComponent extends Input_1.default {
116
117
  parseNumber(value) {
117
118
  // Remove delimiters and convert decimal separator to dot.
118
119
  value = value.split(this.delimiter).join('').replace(this.decimalSeparator, '.');
120
+ // Add support for scientific notation
121
+ if (/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(value)) {
122
+ return Number(value);
123
+ }
119
124
  if (this.component.validate && this.component.validate.integer) {
120
125
  return parseInt(value, 10);
121
126
  }
@@ -171,8 +176,17 @@ class NumberComponent extends Input_1.default {
171
176
  input = input.split(this.delimiter).join('').replace(this.decimalSeparator, '.');
172
177
  }
173
178
  let value = parseFloat(input);
179
+ if (this.component.allowScientificNotation) {
180
+ value = Number(input);
181
+ }
174
182
  if (!lodash_1.default.isNaN(value)) {
175
- value = String(value).replace('.', this.decimalSeparator);
183
+ // Format scientific notation
184
+ if (/e/i.test(String(value))) {
185
+ value = value.toExponential(this.decimalLimit);
186
+ }
187
+ else {
188
+ value = String(value).replace('.', this.decimalSeparator);
189
+ }
176
190
  }
177
191
  else {
178
192
  value = null;
@@ -25,6 +25,14 @@ exports.default = [
25
25
  label: 'Require Decimal',
26
26
  tooltip: 'Always show decimals, even if trailing zeros.'
27
27
  },
28
+ {
29
+ type: 'checkbox',
30
+ input: true,
31
+ weight: 100,
32
+ key: 'allowScientificNotation',
33
+ label: 'Allow Scientific Notation',
34
+ tooltip: 'Allow scientific notation for numbers.'
35
+ },
28
36
  {
29
37
  key: 'case',
30
38
  ignore: true,
@@ -7,7 +7,7 @@ import { Formio } from "./Formio";
7
7
  import Components from "./components/Components";
8
8
  import NestedDataComponent from "./components/_classes/nesteddata/NestedDataComponent";
9
9
  import { fastCloneDeep, currentTimezone, unescapeHTML, getStringFromComponentPath, convertStringToHTMLElement, getArrayFromComponentPath, } from "./utils/utils";
10
- import { eachComponent, eachComponentData } from "./utils/formUtils";
10
+ import { eachComponent } from "./utils/formUtils";
11
11
  // We need this here because dragula pulls in CustomEvent class that requires global to exist.
12
12
  if (typeof window !== 'undefined' && typeof window.global === 'undefined') {
13
13
  window.global = window;
@@ -1536,7 +1536,7 @@ export default class Webform extends NestedDataComponent {
1536
1536
  return;
1537
1537
  }
1538
1538
  const captchaComponent = [];
1539
- eachComponentData(this.components, {}, (component) => {
1539
+ eachComponent(this.components, (component) => {
1540
1540
  if (/^(re)?captcha$/.test(component.type) && component.component.eventType === 'formLoad') {
1541
1541
  captchaComponent.push(component);
1542
1542
  }
package/lib/mjs/Wizard.js CHANGED
@@ -903,7 +903,7 @@ export default class Wizard extends Webform {
903
903
  const components = !currentPageOnly || this.isLastPage()
904
904
  ? this.getComponents()
905
905
  : this.currentPage.components;
906
- return components.reduce((check, comp) => comp.checkValidity(data, dirty, row, childErrors) && check, true);
906
+ return components.reduce((check, comp) => comp.checkValidity(data, dirty, row, currentPageOnly, childErrors) && check, true);
907
907
  }
908
908
  get errors() {
909
909
  if (!this.isLastPage()) {
@@ -11,6 +11,7 @@ export default class DayComponent extends Field {
11
11
  operators: string[];
12
12
  };
13
13
  static savedValueTypes(schema: any): string[];
14
+ static oldEmptyValue: string;
14
15
  static get serverConditionSettings(): {
15
16
  operators: string[];
16
17
  };
@@ -49,6 +49,8 @@ export default class DayComponent extends Field {
49
49
  schema = schema || {};
50
50
  return getComponentSavedTypes(schema) || [componentValueTypes.string];
51
51
  }
52
+ // Empty value used before 9.3.x
53
+ static oldEmptyValue = '00/00/0000';
52
54
  constructor(component, options, data) {
53
55
  if (component.maxDate && component.maxDate.indexOf('moment(') === -1) {
54
56
  component.maxDate = moment(component.maxDate, 'YYYY-MM-DD').toISOString();
@@ -102,6 +104,12 @@ export default class DayComponent extends Field {
102
104
  info.changeEvent = 'input';
103
105
  return info;
104
106
  }
107
+ isEmpty(value = this.dataValue) {
108
+ if (value === DayComponent.oldEmptyValue) {
109
+ return true;
110
+ }
111
+ return super.isEmpty(value);
112
+ }
105
113
  inputDefinition(name) {
106
114
  let min, max;
107
115
  if (name === 'day') {
@@ -335,6 +343,10 @@ export default class DayComponent extends Field {
335
343
  }
336
344
  }
337
345
  normalizeValue(value) {
346
+ // Adjust the value from old to new format
347
+ if (value === DayComponent.oldEmptyValue) {
348
+ value = '';
349
+ }
338
350
  if (!value || this.valueMask.test(value)) {
339
351
  return value;
340
352
  }
@@ -82,6 +82,7 @@ export default class NumberComponent extends Input {
82
82
  decimalLimit: _.get(this.component, 'decimalLimit', this.decimalLimit),
83
83
  allowNegative: _.get(this.component, 'allowNegative', true),
84
84
  allowDecimal: this.isDecimalAllowed(),
85
+ allowScientificNotation: _.get(this.component, 'allowScientificNotation', false),
85
86
  });
86
87
  }
87
88
  get defaultSchema() {
@@ -114,6 +115,10 @@ export default class NumberComponent extends Input {
114
115
  parseNumber(value) {
115
116
  // Remove delimiters and convert decimal separator to dot.
116
117
  value = value.split(this.delimiter).join('').replace(this.decimalSeparator, '.');
118
+ // Add support for scientific notation
119
+ if (/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(value)) {
120
+ return Number(value);
121
+ }
117
122
  if (this.component.validate && this.component.validate.integer) {
118
123
  return parseInt(value, 10);
119
124
  }
@@ -169,8 +174,17 @@ export default class NumberComponent extends Input {
169
174
  input = input.split(this.delimiter).join('').replace(this.decimalSeparator, '.');
170
175
  }
171
176
  let value = parseFloat(input);
177
+ if (this.component.allowScientificNotation) {
178
+ value = Number(input);
179
+ }
172
180
  if (!_.isNaN(value)) {
173
- value = String(value).replace('.', this.decimalSeparator);
181
+ // Format scientific notation
182
+ if (/e/i.test(String(value))) {
183
+ value = value.toExponential(this.decimalLimit);
184
+ }
185
+ else {
186
+ value = String(value).replace('.', this.decimalSeparator);
187
+ }
174
188
  }
175
189
  else {
176
190
  value = null;
@@ -23,6 +23,14 @@ export default [
23
23
  label: 'Require Decimal',
24
24
  tooltip: 'Always show decimals, even if trailing zeros.'
25
25
  },
26
+ {
27
+ type: 'checkbox',
28
+ input: true,
29
+ weight: 100,
30
+ key: 'allowScientificNotation',
31
+ label: 'Allow Scientific Notation',
32
+ tooltip: 'Allow scientific notation for numbers.'
33
+ },
26
34
  {
27
35
  key: 'case',
28
36
  ignore: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.0.0-dev.5875.f359435",
3
+ "version": "5.0.0-dev.5878.d6b667a",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {