@formio/js 5.1.0-dev.6101.0682abe → 5.1.0-dev.6104.98e707b

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.
@@ -77,6 +77,7 @@ export default class WebformBuilder extends Component {
77
77
  removeComponent(component: any, parent: any, original: any, componentInstance: any): boolean | undefined;
78
78
  replaceDoubleQuotes(data: any, fieldsToRemoveDoubleQuotes?: any[]): any;
79
79
  updateComponent(component: any, changed: any): void;
80
+ originalDefaultValue: any;
80
81
  findRepeatablePaths(): any[];
81
82
  highlightInvalidComponents(): void;
82
83
  /**
@@ -1070,6 +1070,17 @@ class WebformBuilder extends Component_1.default {
1070
1070
  'fields.month.required',
1071
1071
  'fields.year.required',
1072
1072
  ]));
1073
+ if (defaultValueComponent.component.components) {
1074
+ if (!this.originalDefaultValue) {
1075
+ this.originalDefaultValue = (0, utils_1.fastCloneDeep)(defaultValueComponent.component);
1076
+ }
1077
+ (0, formUtils_1.eachComponent)(defaultValueComponent.component.components, (comp => {
1078
+ var _a;
1079
+ if ((_a = comp.validate) === null || _a === void 0 ? void 0 : _a.required) {
1080
+ comp.validate.required = false;
1081
+ }
1082
+ }));
1083
+ }
1073
1084
  const parentComponent = defaultValueComponent.parent;
1074
1085
  let tabIndex = -1;
1075
1086
  let index = -1;
@@ -1161,6 +1172,9 @@ class WebformBuilder extends Component_1.default {
1161
1172
  if (index !== -1) {
1162
1173
  let submissionData = this.editForm.submission.data;
1163
1174
  submissionData = submissionData.componentJson || submissionData;
1175
+ if (submissionData.components && this.originalDefaultValue) {
1176
+ submissionData.components = this.originalDefaultValue.components;
1177
+ }
1164
1178
  const fieldsToRemoveDoubleQuotes = ['label', 'tooltip'];
1165
1179
  this.replaceDoubleQuotes(submissionData, fieldsToRemoveDoubleQuotes);
1166
1180
  this.hook('beforeSaveComponentSettings', submissionData);
@@ -9,7 +9,7 @@ export default class ButtonComponent extends Field {
9
9
  };
10
10
  static savedValueTypes(schema: any): string[];
11
11
  constructor(component: any, options: any, data: any);
12
- filesUploading: any[];
12
+ filesUploading: number;
13
13
  get inputInfo(): any;
14
14
  get labelInfo(): {
15
15
  hidden: boolean;
@@ -39,7 +39,7 @@ class ButtonComponent extends Field_1.default {
39
39
  }
40
40
  constructor(component, options, data) {
41
41
  super(component, options, data);
42
- this.filesUploading = [];
42
+ this.filesUploading = 0;
43
43
  }
44
44
  get defaultSchema() {
45
45
  return ButtonComponent.schema();
@@ -147,16 +147,13 @@ class ButtonComponent extends Field_1.default {
147
147
  this.addClass(this.refs.buttonMessageContainer, 'has-error');
148
148
  this.setContent(this.refs.buttonMessage, resultMessage);
149
149
  }, true);
150
- this.on('fileUploadingStart', (filePromise) => {
151
- this.filesUploading.push(filePromise);
150
+ this.on('fileUploadingStart', () => {
151
+ this.filesUploading++;
152
152
  this.disabled = true;
153
153
  this.setDisabled(this.refs.button, this.disabled);
154
154
  }, true);
155
- this.on('fileUploadingEnd', (filePromise) => {
156
- const index = this.filesUploading.indexOf(filePromise);
157
- if (index !== -1) {
158
- this.filesUploading.splice(index, 1);
159
- }
155
+ this.on('fileUploadingEnd', () => {
156
+ this.filesUploading--;
160
157
  this.disabled = this.shouldDisabled ? true : false;
161
158
  this.setDisabled(this.refs.button, this.disabled);
162
159
  }, true);
@@ -252,8 +249,7 @@ class ButtonComponent extends Field_1.default {
252
249
  }
253
250
  }
254
251
  get shouldDisabled() {
255
- var _a;
256
- return super.shouldDisabled || !!((_a = this.filesUploading) === null || _a === void 0 ? void 0 : _a.length) || this.isDisabledOnInvalid;
252
+ return super.shouldDisabled || this.filesUploading > 0 || this.isDisabledOnInvalid;
257
253
  }
258
254
  attach(element) {
259
255
  this.loadRefs(element, {
@@ -905,17 +905,16 @@ class FileComponent extends Field_1.default {
905
905
  }
906
906
  uploadFile(fileToSync) {
907
907
  return __awaiter(this, void 0, void 0, function* () {
908
- const filePromise = this.fileService.uploadFile(fileToSync.storage, fileToSync.file, fileToSync.name, fileToSync.dir,
908
+ return yield this.fileService.uploadFile(fileToSync.storage, fileToSync.file, fileToSync.name, fileToSync.dir,
909
909
  // Progress callback
910
910
  this.updateProgress.bind(this, fileToSync), fileToSync.url, fileToSync.options, fileToSync.fileKey, fileToSync.groupPermissions, fileToSync.groupResourceId, () => {
911
- this.emit('fileUploadingStart', filePromise);
911
+ this.emit('fileUploadingStart');
912
912
  },
913
913
  // Abort upload callback
914
914
  (abort) => this.abortUploads.push({
915
915
  id: fileToSync.id,
916
916
  abort,
917
917
  }), this.getMultipartOptions(fileToSync));
918
- return yield filePromise;
919
918
  });
920
919
  }
921
920
  upload() {
@@ -937,7 +936,7 @@ class FileComponent extends Field_1.default {
937
936
  fileToSync.message = this.t('succefullyUploaded');
938
937
  fileInfo.originalName = fileToSync.originalName;
939
938
  fileInfo.hash = fileToSync.hash;
940
- this.emit('fileUploadingEnd', Promise.resolve(fileInfo));
939
+ this.emit('fileUploadingEnd');
941
940
  }
942
941
  catch (response) {
943
942
  fileToSync.status = 'error';
@@ -947,7 +946,7 @@ class FileComponent extends Field_1.default {
947
946
  : response.type === 'abort'
948
947
  ? this.t('Request was aborted')
949
948
  : response.toString();
950
- this.emit('fileUploadingEnd', Promise.reject(response));
949
+ this.emit('fileUploadingEnd');
951
950
  this.emit('fileUploadError', {
952
951
  fileToSync,
953
952
  response,
@@ -28,6 +28,7 @@ export default class RadioComponent extends ListComponent {
28
28
  optionsLoaded: boolean | undefined;
29
29
  loadedOptions: any[] | undefined;
30
30
  beforeSubmit(): Promise<any>;
31
+ convertValues(values: any): any;
31
32
  render(): string;
32
33
  attach(element: any): Promise<void>;
33
34
  detach(element: any): void;
@@ -41,5 +42,12 @@ export default class RadioComponent extends ListComponent {
41
42
  setSelectedClasses(): void;
42
43
  updateValue(value: any, flags: any): boolean;
43
44
  currentValue: any;
45
+ /**
46
+ * Normalize values coming into updateValue. For example, depending on the configuration, string value `"true"` will be normalized to boolean `true`.
47
+ * @param {*} value - The value to normalize
48
+ * @returns {*} - Returns the normalized value
49
+ */
50
+ convertByDataType(value: any): any;
51
+ normalizeValue(value: any): any;
44
52
  }
45
53
  import ListComponent from '../_classes/list/ListComponent';
@@ -153,6 +153,12 @@ class RadioComponent extends ListComponent_1.default {
153
153
  this.dataReady.then(() => res(true));
154
154
  });
155
155
  }
156
+ convertValues(values) {
157
+ if (this.options.renderMode === 'html' && this.type === 'radio') {
158
+ return values.map(x => (Object.assign(Object.assign({}, x), { value: this.convertByDataType(x.value) })));
159
+ }
160
+ return values;
161
+ }
156
162
  render() {
157
163
  if (!this.optionsLoaded) {
158
164
  return super.render(this.renderTemplate('loader'));
@@ -160,7 +166,7 @@ class RadioComponent extends ListComponent_1.default {
160
166
  return super.render(this.renderTemplate('radio', {
161
167
  input: this.inputInfo,
162
168
  inline: this.component.inline,
163
- values: this.component.dataSrc === 'values' ? this.component.values : this.loadedOptions,
169
+ values: this.component.dataSrc === 'values' ? this.convertValues(this.component.values) : this.loadedOptions,
164
170
  value: this.dataValue,
165
171
  row: this.row,
166
172
  }));
@@ -406,7 +412,7 @@ class RadioComponent extends ListComponent_1.default {
406
412
  * @param {*} value - The value to normalize
407
413
  * @returns {*} - Returns the normalized value
408
414
  */
409
- normalizeValue(value) {
415
+ convertByDataType(value) {
410
416
  const dataType = this.component.dataType || 'auto';
411
417
  if (value === this.emptyValue) {
412
418
  return value;
@@ -438,14 +444,18 @@ class RadioComponent extends ListComponent_1.default {
438
444
  value = !(!value || value.toString() === 'false');
439
445
  break;
440
446
  }
441
- if (this.isSelectURL && this.templateData && this.templateData[value]) {
447
+ return value;
448
+ }
449
+ normalizeValue(value) {
450
+ const valueConverted = this.convertByDataType(value);
451
+ if (this.isSelectURL && this.templateData && this.templateData[valueConverted]) {
442
452
  const submission = this.root.submission;
443
453
  if (!submission.metadata.selectData) {
444
454
  submission.metadata.selectData = {};
445
455
  }
446
- lodash_1.default.set(submission.metadata.selectData, this.path, this.templateData[value]);
456
+ lodash_1.default.set(submission.metadata.selectData, this.path, this.templateData[valueConverted]);
447
457
  }
448
- return super.normalizeValue(value);
458
+ return super.normalizeValue(valueConverted);
449
459
  }
450
460
  }
451
461
  exports.default = RadioComponent;
@@ -8,6 +8,12 @@ export default class SelectBoxesComponent extends RadioComponent {
8
8
  * @returns {boolean} - If the value is empty.
9
9
  */
10
10
  isEmpty(value?: any): boolean;
11
+ /**
12
+ * Normalize values coming into updateValue.
13
+ * @param {any} value - The value to normalize.
14
+ * @returns {*} - The normalized value
15
+ */
16
+ normalizeValue(value: any): any;
11
17
  setInputsDisabled(value: any, onlyUnchecked: any): void;
12
18
  checkComponentValidity(data: any, dirty: any, rowData: any, options: any, errors?: any[]): boolean;
13
19
  }
@@ -27,7 +27,7 @@ class FormioUploadAdapter {
27
27
  null,
28
28
  null
29
29
  ];
30
- const uploadPromise = this.fileService.uploadFile(...uploadParams, () => this.component.emit('fileUploadingStart', uploadPromise)).then((result) => {
30
+ this.fileService.uploadFile(...uploadParams, () => this.component.emit('fileUploadingStart')).then((result) => {
31
31
  return this.fileService.downloadFile(result);
32
32
  }).then((result) => {
33
33
  return resolve({
@@ -37,7 +37,7 @@ class FormioUploadAdapter {
37
37
  console.warn('An Error occured while uploading file', err);
38
38
  reject(err);
39
39
  }).finally(() => {
40
- this.component.emit('fileUploadingEnd', uploadPromise);
40
+ this.component.emit('fileUploadingEnd');
41
41
  });
42
42
  }));
43
43
  }
@@ -77,6 +77,7 @@ export default class WebformBuilder extends Component {
77
77
  removeComponent(component: any, parent: any, original: any, componentInstance: any): boolean | undefined;
78
78
  replaceDoubleQuotes(data: any, fieldsToRemoveDoubleQuotes?: any[]): any;
79
79
  updateComponent(component: any, changed: any): void;
80
+ originalDefaultValue: any;
80
81
  findRepeatablePaths(): any[];
81
82
  highlightInvalidComponents(): void;
82
83
  /**
@@ -1054,6 +1054,16 @@ export default class WebformBuilder extends Component {
1054
1054
  'fields.month.required',
1055
1055
  'fields.year.required',
1056
1056
  ]));
1057
+ if (defaultValueComponent.component.components) {
1058
+ if (!this.originalDefaultValue) {
1059
+ this.originalDefaultValue = fastCloneDeep(defaultValueComponent.component);
1060
+ }
1061
+ eachComponent(defaultValueComponent.component.components, (comp => {
1062
+ if (comp.validate?.required) {
1063
+ comp.validate.required = false;
1064
+ }
1065
+ }));
1066
+ }
1057
1067
  const parentComponent = defaultValueComponent.parent;
1058
1068
  let tabIndex = -1;
1059
1069
  let index = -1;
@@ -1145,6 +1155,9 @@ export default class WebformBuilder extends Component {
1145
1155
  if (index !== -1) {
1146
1156
  let submissionData = this.editForm.submission.data;
1147
1157
  submissionData = submissionData.componentJson || submissionData;
1158
+ if (submissionData.components && this.originalDefaultValue) {
1159
+ submissionData.components = this.originalDefaultValue.components;
1160
+ }
1148
1161
  const fieldsToRemoveDoubleQuotes = ['label', 'tooltip'];
1149
1162
  this.replaceDoubleQuotes(submissionData, fieldsToRemoveDoubleQuotes);
1150
1163
  this.hook('beforeSaveComponentSettings', submissionData);
@@ -9,7 +9,7 @@ export default class ButtonComponent extends Field {
9
9
  };
10
10
  static savedValueTypes(schema: any): string[];
11
11
  constructor(component: any, options: any, data: any);
12
- filesUploading: any[];
12
+ filesUploading: number;
13
13
  get inputInfo(): any;
14
14
  get labelInfo(): {
15
15
  hidden: boolean;
@@ -34,7 +34,7 @@ export default class ButtonComponent extends Field {
34
34
  }
35
35
  constructor(component, options, data) {
36
36
  super(component, options, data);
37
- this.filesUploading = [];
37
+ this.filesUploading = 0;
38
38
  }
39
39
  get defaultSchema() {
40
40
  return ButtonComponent.schema();
@@ -142,16 +142,13 @@ export default class ButtonComponent extends Field {
142
142
  this.addClass(this.refs.buttonMessageContainer, 'has-error');
143
143
  this.setContent(this.refs.buttonMessage, resultMessage);
144
144
  }, true);
145
- this.on('fileUploadingStart', (filePromise) => {
146
- this.filesUploading.push(filePromise);
145
+ this.on('fileUploadingStart', () => {
146
+ this.filesUploading++;
147
147
  this.disabled = true;
148
148
  this.setDisabled(this.refs.button, this.disabled);
149
149
  }, true);
150
- this.on('fileUploadingEnd', (filePromise) => {
151
- const index = this.filesUploading.indexOf(filePromise);
152
- if (index !== -1) {
153
- this.filesUploading.splice(index, 1);
154
- }
150
+ this.on('fileUploadingEnd', () => {
151
+ this.filesUploading--;
155
152
  this.disabled = this.shouldDisabled ? true : false;
156
153
  this.setDisabled(this.refs.button, this.disabled);
157
154
  }, true);
@@ -247,7 +244,7 @@ export default class ButtonComponent extends Field {
247
244
  }
248
245
  }
249
246
  get shouldDisabled() {
250
- return super.shouldDisabled || !!this.filesUploading?.length || this.isDisabledOnInvalid;
247
+ return super.shouldDisabled || this.filesUploading > 0 || this.isDisabledOnInvalid;
251
248
  }
252
249
  attach(element) {
253
250
  this.loadRefs(element, {
@@ -903,17 +903,16 @@ export default class FileComponent extends Field {
903
903
  } : false;
904
904
  }
905
905
  async uploadFile(fileToSync) {
906
- const filePromise = this.fileService.uploadFile(fileToSync.storage, fileToSync.file, fileToSync.name, fileToSync.dir,
906
+ return await this.fileService.uploadFile(fileToSync.storage, fileToSync.file, fileToSync.name, fileToSync.dir,
907
907
  // Progress callback
908
908
  this.updateProgress.bind(this, fileToSync), fileToSync.url, fileToSync.options, fileToSync.fileKey, fileToSync.groupPermissions, fileToSync.groupResourceId, () => {
909
- this.emit('fileUploadingStart', filePromise);
909
+ this.emit('fileUploadingStart');
910
910
  },
911
911
  // Abort upload callback
912
912
  (abort) => this.abortUploads.push({
913
913
  id: fileToSync.id,
914
914
  abort,
915
915
  }), this.getMultipartOptions(fileToSync));
916
- return await filePromise;
917
916
  }
918
917
  async upload() {
919
918
  if (!this.filesToSync.filesToUpload.length) {
@@ -933,7 +932,7 @@ export default class FileComponent extends Field {
933
932
  fileToSync.message = this.t('succefullyUploaded');
934
933
  fileInfo.originalName = fileToSync.originalName;
935
934
  fileInfo.hash = fileToSync.hash;
936
- this.emit('fileUploadingEnd', Promise.resolve(fileInfo));
935
+ this.emit('fileUploadingEnd');
937
936
  }
938
937
  catch (response) {
939
938
  fileToSync.status = 'error';
@@ -943,7 +942,7 @@ export default class FileComponent extends Field {
943
942
  : response.type === 'abort'
944
943
  ? this.t('Request was aborted')
945
944
  : response.toString();
946
- this.emit('fileUploadingEnd', Promise.reject(response));
945
+ this.emit('fileUploadingEnd');
947
946
  this.emit('fileUploadError', {
948
947
  fileToSync,
949
948
  response,
@@ -28,6 +28,7 @@ export default class RadioComponent extends ListComponent {
28
28
  optionsLoaded: boolean | undefined;
29
29
  loadedOptions: any[] | undefined;
30
30
  beforeSubmit(): Promise<any>;
31
+ convertValues(values: any): any;
31
32
  render(): string;
32
33
  attach(element: any): Promise<void>;
33
34
  detach(element: any): void;
@@ -41,5 +42,12 @@ export default class RadioComponent extends ListComponent {
41
42
  setSelectedClasses(): void;
42
43
  updateValue(value: any, flags: any): boolean;
43
44
  currentValue: any;
45
+ /**
46
+ * Normalize values coming into updateValue. For example, depending on the configuration, string value `"true"` will be normalized to boolean `true`.
47
+ * @param {*} value - The value to normalize
48
+ * @returns {*} - Returns the normalized value
49
+ */
50
+ convertByDataType(value: any): any;
51
+ normalizeValue(value: any): any;
44
52
  }
45
53
  import ListComponent from '../_classes/list/ListComponent';
@@ -153,6 +153,12 @@ export default class RadioComponent extends ListComponent {
153
153
  this.dataReady.then(() => res(true));
154
154
  });
155
155
  }
156
+ convertValues(values) {
157
+ if (this.options.renderMode === 'html' && this.type === 'radio') {
158
+ return values.map(x => ({ ...x, value: this.convertByDataType(x.value) }));
159
+ }
160
+ return values;
161
+ }
156
162
  render() {
157
163
  if (!this.optionsLoaded) {
158
164
  return super.render(this.renderTemplate('loader'));
@@ -160,7 +166,7 @@ export default class RadioComponent extends ListComponent {
160
166
  return super.render(this.renderTemplate('radio', {
161
167
  input: this.inputInfo,
162
168
  inline: this.component.inline,
163
- values: this.component.dataSrc === 'values' ? this.component.values : this.loadedOptions,
169
+ values: this.component.dataSrc === 'values' ? this.convertValues(this.component.values) : this.loadedOptions,
164
170
  value: this.dataValue,
165
171
  row: this.row,
166
172
  }));
@@ -406,7 +412,7 @@ export default class RadioComponent extends ListComponent {
406
412
  * @param {*} value - The value to normalize
407
413
  * @returns {*} - Returns the normalized value
408
414
  */
409
- normalizeValue(value) {
415
+ convertByDataType(value) {
410
416
  const dataType = this.component.dataType || 'auto';
411
417
  if (value === this.emptyValue) {
412
418
  return value;
@@ -438,13 +444,17 @@ export default class RadioComponent extends ListComponent {
438
444
  value = !(!value || value.toString() === 'false');
439
445
  break;
440
446
  }
441
- if (this.isSelectURL && this.templateData && this.templateData[value]) {
447
+ return value;
448
+ }
449
+ normalizeValue(value) {
450
+ const valueConverted = this.convertByDataType(value);
451
+ if (this.isSelectURL && this.templateData && this.templateData[valueConverted]) {
442
452
  const submission = this.root.submission;
443
453
  if (!submission.metadata.selectData) {
444
454
  submission.metadata.selectData = {};
445
455
  }
446
- _.set(submission.metadata.selectData, this.path, this.templateData[value]);
456
+ _.set(submission.metadata.selectData, this.path, this.templateData[valueConverted]);
447
457
  }
448
- return super.normalizeValue(value);
458
+ return super.normalizeValue(valueConverted);
449
459
  }
450
460
  }
@@ -8,6 +8,12 @@ export default class SelectBoxesComponent extends RadioComponent {
8
8
  * @returns {boolean} - If the value is empty.
9
9
  */
10
10
  isEmpty(value?: any): boolean;
11
+ /**
12
+ * Normalize values coming into updateValue.
13
+ * @param {any} value - The value to normalize.
14
+ * @returns {*} - The normalized value
15
+ */
16
+ normalizeValue(value: any): any;
11
17
  setInputsDisabled(value: any, onlyUnchecked: any): void;
12
18
  checkComponentValidity(data: any, dirty: any, rowData: any, options: any, errors?: any[]): boolean;
13
19
  }
@@ -24,7 +24,7 @@ class FormioUploadAdapter {
24
24
  null,
25
25
  null
26
26
  ];
27
- const uploadPromise = this.fileService.uploadFile(...uploadParams, () => this.component.emit('fileUploadingStart', uploadPromise)).then((result) => {
27
+ this.fileService.uploadFile(...uploadParams, () => this.component.emit('fileUploadingStart')).then((result) => {
28
28
  return this.fileService.downloadFile(result);
29
29
  }).then((result) => {
30
30
  return resolve({
@@ -34,7 +34,7 @@ class FormioUploadAdapter {
34
34
  console.warn('An Error occured while uploading file', err);
35
35
  reject(err);
36
36
  }).finally(() => {
37
- this.component.emit('fileUploadingEnd', uploadPromise);
37
+ this.component.emit('fileUploadingEnd');
38
38
  });
39
39
  }));
40
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.1.0-dev.6101.0682abe",
3
+ "version": "5.1.0-dev.6104.98e707b",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {