@formio/js 5.0.0-dev.5850.b6b5101 → 5.0.0-dev.5855.daa98f8

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.
@@ -1237,9 +1237,15 @@ class Webform extends NestedDataComponent_1.default {
1237
1237
  * @param {any} changes - The changes that have occured in the form.
1238
1238
  */
1239
1239
  onChange(flags, changed, modified, changes) {
1240
+ var _a;
1240
1241
  flags = flags || {};
1241
1242
  let isChangeEventEmitted = false;
1242
- super.onChange(flags, true);
1243
+ if (((_a = this.parent) === null || _a === void 0 ? void 0 : _a.subForm) === this) {
1244
+ super.onChange(Object.assign(Object.assign({}, flags), { modified }), false);
1245
+ }
1246
+ else {
1247
+ super.onChange(flags, true);
1248
+ }
1243
1249
  const value = lodash_1.default.clone(this.submission);
1244
1250
  flags.changed = value.changed = changed;
1245
1251
  flags.changes = changes;
@@ -13,6 +13,7 @@ const utils_1 = require("../../utils/utils");
13
13
  const EditRowState = {
14
14
  New: 'new',
15
15
  Editing: 'editing',
16
+ Saving: 'saving',
16
17
  Saved: 'saved',
17
18
  Viewing: 'viewing',
18
19
  Removed: 'removed',
@@ -808,6 +809,10 @@ class EditGridComponent extends NestedArrayComponent_1.default {
808
809
  if (!this.component.rowDrafts) {
809
810
  editRow.components.forEach((comp) => comp.setPristine(false));
810
811
  }
812
+ // Mark the row with a 'Saving' state to trigger validation for future row changes
813
+ if (editRow.state === EditRowState.New) {
814
+ editRow.state = EditRowState.Saving;
815
+ }
811
816
  const errors = this.validateRow(editRow, true);
812
817
  if (!this.component.rowDrafts) {
813
818
  if (errors.length) {
@@ -820,7 +825,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
820
825
  this.root.focusedComponent = null;
821
826
  }
822
827
  switch (editRow.state) {
823
- case EditRowState.New: {
828
+ case EditRowState.Saving: {
824
829
  const newIndex = dataValue.length;
825
830
  dataValue.push(editRow.data);
826
831
  editRow.components.forEach(component => component.rowIndex = newIndex);
@@ -980,7 +985,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
980
985
  }
981
986
  shouldValidateRow(editRow, dirty) {
982
987
  return this.shouldValidateDraft(editRow) ||
983
- editRow.state === EditRowState.New ||
988
+ editRow.state === EditRowState.Saving ||
984
989
  editRow.state === EditRowState.Editing ||
985
990
  editRow.alerts ||
986
991
  dirty;
@@ -1084,6 +1089,7 @@ class EditGridComponent extends NestedArrayComponent_1.default {
1084
1089
  }
1085
1090
  else if (errorContainer) {
1086
1091
  errorContainer.textContent = '';
1092
+ this.removeClass(errorContainer, 'help-block');
1087
1093
  }
1088
1094
  }
1089
1095
  }
@@ -246,7 +246,11 @@ class SelectComponent extends ListComponent_1.default {
246
246
  const value = (typeof itemLabel === 'string') ? this.t(itemLabel, { _userInput: true }) : itemLabel;
247
247
  return this.sanitize(value, this.shouldSanitizeValue);
248
248
  }
249
- if (this.component.multiple && lodash_1.default.isArray(this.dataValue) ? this.dataValue.find((val) => this.normalizeSingleValue(value) === val) : (this.dataValue === this.normalizeSingleValue(value))) {
249
+ // Inside DataTable component won't have dataValue set
250
+ const shouldUseSelectData = (this.component.multiple && lodash_1.default.isArray(this.dataValue)
251
+ ? this.dataValue.find((val) => this.normalizeSingleValue(value) === val)
252
+ : (this.dataValue === this.normalizeSingleValue(value))) || this.inDataTable;
253
+ if (shouldUseSelectData) {
250
254
  const selectData = this.selectData;
251
255
  if (selectData) {
252
256
  const templateValue = this.component.reference && (value === null || value === void 0 ? void 0 : value._id) ? value._id.toString() : value;
@@ -1213,7 +1217,7 @@ class SelectComponent extends ListComponent_1.default {
1213
1217
  // Check to see if we need to save off the template data into our metadata.
1214
1218
  const templateValue = this.component.reference && (value === null || value === void 0 ? void 0 : value._id) ? value._id.toString() : value;
1215
1219
  const shouldSaveData = !valueIsObject || this.component.reference;
1216
- if (templateValue && shouldSaveData && this.templateData && this.templateData[templateValue] && ((_a = this.root) === null || _a === void 0 ? void 0 : _a.submission)) {
1220
+ if (!lodash_1.default.isNil(templateValue) && shouldSaveData && this.templateData && this.templateData[templateValue] && ((_a = this.root) === null || _a === void 0 ? void 0 : _a.submission)) {
1217
1221
  const submission = this.root.submission;
1218
1222
  if (!submission.metadata) {
1219
1223
  submission.metadata = {};
@@ -1468,8 +1472,12 @@ class SelectComponent extends ListComponent_1.default {
1468
1472
  asString(value, options = {}) {
1469
1473
  var _a;
1470
1474
  value = value !== null && value !== void 0 ? value : this.getValue();
1471
- if (options.modalPreview) {
1472
- const template = this.itemTemplate(value, value);
1475
+ if (options.modalPreview || this.inDataTable) {
1476
+ if (this.inDataTable) {
1477
+ value = this.undoValueTyping(value);
1478
+ }
1479
+ const templateValue = (this.isEntireObjectDisplay() && !lodash_1.default.isObject(value.data)) ? { data: value } : value;
1480
+ const template = this.itemTemplate(templateValue, value, options);
1473
1481
  return template;
1474
1482
  }
1475
1483
  //need to convert values to strings to be able to compare values with available options that are strings
@@ -1241,7 +1241,12 @@ export default class Webform extends NestedDataComponent {
1241
1241
  onChange(flags, changed, modified, changes) {
1242
1242
  flags = flags || {};
1243
1243
  let isChangeEventEmitted = false;
1244
- super.onChange(flags, true);
1244
+ if (this.parent?.subForm === this) {
1245
+ super.onChange({ ...flags, modified }, false);
1246
+ }
1247
+ else {
1248
+ super.onChange(flags, true);
1249
+ }
1245
1250
  const value = _.clone(this.submission);
1246
1251
  flags.changed = value.changed = changed;
1247
1252
  flags.changes = changes;
@@ -8,6 +8,7 @@ import { fastCloneDeep, Evaluator, getArrayFromComponentPath, eachComponent } fr
8
8
  const EditRowState = {
9
9
  New: 'new',
10
10
  Editing: 'editing',
11
+ Saving: 'saving',
11
12
  Saved: 'saved',
12
13
  Viewing: 'viewing',
13
14
  Removed: 'removed',
@@ -798,6 +799,10 @@ export default class EditGridComponent extends NestedArrayComponent {
798
799
  if (!this.component.rowDrafts) {
799
800
  editRow.components.forEach((comp) => comp.setPristine(false));
800
801
  }
802
+ // Mark the row with a 'Saving' state to trigger validation for future row changes
803
+ if (editRow.state === EditRowState.New) {
804
+ editRow.state = EditRowState.Saving;
805
+ }
801
806
  const errors = this.validateRow(editRow, true);
802
807
  if (!this.component.rowDrafts) {
803
808
  if (errors.length) {
@@ -810,7 +815,7 @@ export default class EditGridComponent extends NestedArrayComponent {
810
815
  this.root.focusedComponent = null;
811
816
  }
812
817
  switch (editRow.state) {
813
- case EditRowState.New: {
818
+ case EditRowState.Saving: {
814
819
  const newIndex = dataValue.length;
815
820
  dataValue.push(editRow.data);
816
821
  editRow.components.forEach(component => component.rowIndex = newIndex);
@@ -970,7 +975,7 @@ export default class EditGridComponent extends NestedArrayComponent {
970
975
  }
971
976
  shouldValidateRow(editRow, dirty) {
972
977
  return this.shouldValidateDraft(editRow) ||
973
- editRow.state === EditRowState.New ||
978
+ editRow.state === EditRowState.Saving ||
974
979
  editRow.state === EditRowState.Editing ||
975
980
  editRow.alerts ||
976
981
  dirty;
@@ -1072,6 +1077,7 @@ export default class EditGridComponent extends NestedArrayComponent {
1072
1077
  }
1073
1078
  else if (errorContainer) {
1074
1079
  errorContainer.textContent = '';
1080
+ this.removeClass(errorContainer, 'help-block');
1075
1081
  }
1076
1082
  }
1077
1083
  }
@@ -246,7 +246,11 @@ export default class SelectComponent extends ListComponent {
246
246
  const value = (typeof itemLabel === 'string') ? this.t(itemLabel, { _userInput: true }) : itemLabel;
247
247
  return this.sanitize(value, this.shouldSanitizeValue);
248
248
  }
249
- if (this.component.multiple && _.isArray(this.dataValue) ? this.dataValue.find((val) => this.normalizeSingleValue(value) === val) : (this.dataValue === this.normalizeSingleValue(value))) {
249
+ // Inside DataTable component won't have dataValue set
250
+ const shouldUseSelectData = (this.component.multiple && _.isArray(this.dataValue)
251
+ ? this.dataValue.find((val) => this.normalizeSingleValue(value) === val)
252
+ : (this.dataValue === this.normalizeSingleValue(value))) || this.inDataTable;
253
+ if (shouldUseSelectData) {
250
254
  const selectData = this.selectData;
251
255
  if (selectData) {
252
256
  const templateValue = this.component.reference && value?._id ? value._id.toString() : value;
@@ -1241,7 +1245,7 @@ export default class SelectComponent extends ListComponent {
1241
1245
  // Check to see if we need to save off the template data into our metadata.
1242
1246
  const templateValue = this.component.reference && value?._id ? value._id.toString() : value;
1243
1247
  const shouldSaveData = !valueIsObject || this.component.reference;
1244
- if (templateValue && shouldSaveData && this.templateData && this.templateData[templateValue] && this.root?.submission) {
1248
+ if (!_.isNil(templateValue) && shouldSaveData && this.templateData && this.templateData[templateValue] && this.root?.submission) {
1245
1249
  const submission = this.root.submission;
1246
1250
  if (!submission.metadata) {
1247
1251
  submission.metadata = {};
@@ -1495,8 +1499,12 @@ export default class SelectComponent extends ListComponent {
1495
1499
  }
1496
1500
  asString(value, options = {}) {
1497
1501
  value = value ?? this.getValue();
1498
- if (options.modalPreview) {
1499
- const template = this.itemTemplate(value, value);
1502
+ if (options.modalPreview || this.inDataTable) {
1503
+ if (this.inDataTable) {
1504
+ value = this.undoValueTyping(value);
1505
+ }
1506
+ const templateValue = (this.isEntireObjectDisplay() && !_.isObject(value.data)) ? { data: value } : value;
1507
+ const template = this.itemTemplate(templateValue, value, options);
1500
1508
  return template;
1501
1509
  }
1502
1510
  //need to convert values to strings to be able to compare values with available options that are strings
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.0.0-dev.5850.b6b5101",
3
+ "version": "5.0.0-dev.5855.daa98f8",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {