@formio/js 5.0.0-dev.5873.124778a → 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.
@@ -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,
@@ -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.5873.124778a",
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": {