@formio/js 5.0.0-dev.5860.a296208 → 5.0.0-dev.5864.1cff328

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.
@@ -1757,12 +1757,12 @@ class Component extends Element_1.default {
1757
1757
  var _a, _b, _c;
1758
1758
  if ((_a = this.root) === null || _a === void 0 ? void 0 : _a.currentSelection) {
1759
1759
  if ((_b = this.refs.input) === null || _b === void 0 ? void 0 : _b.length) {
1760
- const { selection, index } = this.root.currentSelection;
1760
+ const { index } = this.root.currentSelection;
1761
1761
  let input = this.refs.input[index];
1762
1762
  const isInputRangeSelectable = (i) => /text|search|password|tel|url/i.test((i === null || i === void 0 ? void 0 : i.type) || '');
1763
1763
  if (input) {
1764
1764
  if (isInputRangeSelectable(input)) {
1765
- input.setSelectionRange(...selection);
1765
+ input.setSelectionRange(input.value.length, input.value.length);
1766
1766
  }
1767
1767
  }
1768
1768
  else {
@@ -2962,12 +2962,14 @@ class Component extends Element_1.default {
2962
2962
  if (flags.silentCheck) {
2963
2963
  return [];
2964
2964
  }
2965
- let isDirty = this.dirty || flags.dirty;
2966
2965
  if (this.options.alwaysDirty) {
2967
- isDirty = true;
2966
+ flags.dirty = true;
2968
2967
  }
2969
- this.setDirty(isDirty);
2970
- return this.setComponentValidity(errors, isDirty, flags.silentCheck, flags.fromSubmission);
2968
+ if (flags.fromSubmission && this.hasValue(data)) {
2969
+ flags.dirty = this.pristine && this.component.protected ? false : true;
2970
+ }
2971
+ this.setDirty(flags.dirty);
2972
+ return this.setComponentValidity(errors, flags.dirty, flags.silentCheck, flags.fromSubmission);
2971
2973
  }
2972
2974
  /**
2973
2975
  * Perform a component validation.
@@ -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
  }
@@ -584,6 +594,9 @@ class DayComponent extends Field_1.default {
584
594
  * @returns {string|null} - The string value of the date.
585
595
  */
586
596
  getValueAsString(value) {
597
+ if (!value) {
598
+ return '';
599
+ }
587
600
  return this.getDate(value) || '';
588
601
  }
589
602
  focus(field) {
@@ -640,4 +653,6 @@ class DayComponent extends Field_1.default {
640
653
  return validationFormat;
641
654
  }
642
655
  }
656
+ // Empty value used before 9.3.x
657
+ DayComponent.oldEmptyValue = '00/00/0000';
643
658
  exports.default = DayComponent;
@@ -89,8 +89,8 @@ export default class EditGridComponent extends NestedArrayComponent {
89
89
  hasOpenRows(): any;
90
90
  getAttachedData(data?: null): any;
91
91
  shouldValidateDraft(editRow: any): any;
92
- shouldValidateRow(editRow: any, dirty: any, fromSubmission: any): any;
93
- validateRow(editRow: any, dirty: any, forceSilentCheck: any, fromSubmission: any): any;
92
+ shouldValidateRow(editRow: any, dirty: any): any;
93
+ validateRow(editRow: any, dirty: any, forceSilentCheck: any): any;
94
94
  showRowErrorAlerts(editRow: any, errors: any): void;
95
95
  /**
96
96
  * @returns {boolean} - Return that this component processes its own validation.
@@ -983,18 +983,17 @@ class EditGridComponent extends NestedArrayComponent_1.default {
983
983
  !this.hasOpenRows()) ||
984
984
  ((_b = this.root) === null || _b === void 0 ? void 0 : _b.submitted);
985
985
  }
986
- shouldValidateRow(editRow, dirty, fromSubmission) {
986
+ shouldValidateRow(editRow, dirty) {
987
987
  return this.shouldValidateDraft(editRow) ||
988
988
  editRow.state === EditRowState.Saving ||
989
989
  editRow.state === EditRowState.Editing ||
990
990
  editRow.alerts ||
991
- fromSubmission ||
992
991
  dirty;
993
992
  }
994
- validateRow(editRow, dirty, forceSilentCheck, fromSubmission) {
993
+ validateRow(editRow, dirty, forceSilentCheck) {
995
994
  var _a;
996
995
  editRow.errors = [];
997
- if (this.shouldValidateRow(editRow, dirty, fromSubmission)) {
996
+ if (this.shouldValidateRow(editRow, dirty)) {
998
997
  const silentCheck = (this.component.rowDrafts && !this.shouldValidateDraft(editRow)) || forceSilentCheck;
999
998
  const rootValue = (0, utils_1.fastCloneDeep)(this.rootValue);
1000
999
  const editGridValue = lodash_1.default.get(rootValue, this.path, []);
@@ -1066,7 +1065,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
1066
1065
  }
1067
1066
  checkComponentValidity(data, dirty, row, options = {}, errors = []) {
1068
1067
  var _a, _b;
1069
- const { silentCheck, fromSubmission } = options;
1068
+ const { silentCheck } = options;
1070
1069
  const superValid = super.checkComponentValidity(data, dirty, row, options, errors);
1071
1070
  // If super tells us that component invalid and there is no need to update alerts, just return false
1072
1071
  if (!superValid && (!this.alert && !this.hasOpenRows())) {
@@ -1076,7 +1075,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
1076
1075
  const allRowErrors = [];
1077
1076
  this.editRows.forEach((editRow, index) => {
1078
1077
  // Trigger all errors on the row.
1079
- const rowErrors = this.validateRow(editRow, dirty, silentCheck, fromSubmission);
1078
+ const rowErrors = this.validateRow(editRow, dirty, silentCheck);
1080
1079
  errors.push(...rowErrors);
1081
1080
  allRowErrors.push(...rowErrors);
1082
1081
  if (this.rowRefs) {
@@ -1720,12 +1720,12 @@ export default class Component extends Element {
1720
1720
  restoreCaretPosition() {
1721
1721
  if (this.root?.currentSelection) {
1722
1722
  if (this.refs.input?.length) {
1723
- const { selection, index } = this.root.currentSelection;
1723
+ const { index } = this.root.currentSelection;
1724
1724
  let input = this.refs.input[index];
1725
1725
  const isInputRangeSelectable = (i) => /text|search|password|tel|url/i.test(i?.type || '');
1726
1726
  if (input) {
1727
1727
  if (isInputRangeSelectable(input)) {
1728
- input.setSelectionRange(...selection);
1728
+ input.setSelectionRange(input.value.length, input.value.length);
1729
1729
  }
1730
1730
  }
1731
1731
  else {
@@ -2926,12 +2926,14 @@ export default class Component extends Element {
2926
2926
  if (flags.silentCheck) {
2927
2927
  return [];
2928
2928
  }
2929
- let isDirty = this.dirty || flags.dirty;
2930
2929
  if (this.options.alwaysDirty) {
2931
- isDirty = true;
2930
+ flags.dirty = true;
2932
2931
  }
2933
- this.setDirty(isDirty);
2934
- return this.setComponentValidity(errors, isDirty, flags.silentCheck, flags.fromSubmission);
2932
+ if (flags.fromSubmission && this.hasValue(data)) {
2933
+ flags.dirty = this.pristine && this.component.protected ? false : true;
2934
+ }
2935
+ this.setDirty(flags.dirty);
2936
+ return this.setComponentValidity(errors, flags.dirty, flags.silentCheck, flags.fromSubmission);
2935
2937
  }
2936
2938
  /**
2937
2939
  * Perform a component validation.
@@ -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
  }
@@ -582,6 +594,9 @@ export default class DayComponent extends Field {
582
594
  * @returns {string|null} - The string value of the date.
583
595
  */
584
596
  getValueAsString(value) {
597
+ if (!value) {
598
+ return '';
599
+ }
585
600
  return this.getDate(value) || '';
586
601
  }
587
602
  focus(field) {
@@ -89,8 +89,8 @@ export default class EditGridComponent extends NestedArrayComponent {
89
89
  hasOpenRows(): any;
90
90
  getAttachedData(data?: null): any;
91
91
  shouldValidateDraft(editRow: any): any;
92
- shouldValidateRow(editRow: any, dirty: any, fromSubmission: any): any;
93
- validateRow(editRow: any, dirty: any, forceSilentCheck: any, fromSubmission: any): any;
92
+ shouldValidateRow(editRow: any, dirty: any): any;
93
+ validateRow(editRow: any, dirty: any, forceSilentCheck: any): any;
94
94
  showRowErrorAlerts(editRow: any, errors: any): void;
95
95
  /**
96
96
  * @returns {boolean} - Return that this component processes its own validation.
@@ -973,17 +973,16 @@ export default class EditGridComponent extends NestedArrayComponent {
973
973
  !this.hasOpenRows()) ||
974
974
  this.root?.submitted;
975
975
  }
976
- shouldValidateRow(editRow, dirty, fromSubmission) {
976
+ shouldValidateRow(editRow, dirty) {
977
977
  return this.shouldValidateDraft(editRow) ||
978
978
  editRow.state === EditRowState.Saving ||
979
979
  editRow.state === EditRowState.Editing ||
980
980
  editRow.alerts ||
981
- fromSubmission ||
982
981
  dirty;
983
982
  }
984
- validateRow(editRow, dirty, forceSilentCheck, fromSubmission) {
983
+ validateRow(editRow, dirty, forceSilentCheck) {
985
984
  editRow.errors = [];
986
- if (this.shouldValidateRow(editRow, dirty, fromSubmission)) {
985
+ if (this.shouldValidateRow(editRow, dirty)) {
987
986
  const silentCheck = (this.component.rowDrafts && !this.shouldValidateDraft(editRow)) || forceSilentCheck;
988
987
  const rootValue = fastCloneDeep(this.rootValue);
989
988
  const editGridValue = _.get(rootValue, this.path, []);
@@ -1054,7 +1053,7 @@ export default class EditGridComponent extends NestedArrayComponent {
1054
1053
  return true;
1055
1054
  }
1056
1055
  checkComponentValidity(data, dirty, row, options = {}, errors = []) {
1057
- const { silentCheck, fromSubmission } = options;
1056
+ const { silentCheck } = options;
1058
1057
  const superValid = super.checkComponentValidity(data, dirty, row, options, errors);
1059
1058
  // If super tells us that component invalid and there is no need to update alerts, just return false
1060
1059
  if (!superValid && (!this.alert && !this.hasOpenRows())) {
@@ -1064,7 +1063,7 @@ export default class EditGridComponent extends NestedArrayComponent {
1064
1063
  const allRowErrors = [];
1065
1064
  this.editRows.forEach((editRow, index) => {
1066
1065
  // Trigger all errors on the row.
1067
- const rowErrors = this.validateRow(editRow, dirty, silentCheck, fromSubmission);
1066
+ const rowErrors = this.validateRow(editRow, dirty, silentCheck);
1068
1067
  errors.push(...rowErrors);
1069
1068
  allRowErrors.push(...rowErrors);
1070
1069
  if (this.rowRefs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.0.0-dev.5860.a296208",
3
+ "version": "5.0.0-dev.5864.1cff328",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {