@formio/js 5.1.0-dev.6155.8178240 → 5.1.0-dev.6159.811e953

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.
Files changed (41) hide show
  1. package/dist/formio.builder.css +1 -0
  2. package/dist/formio.builder.min.css +1 -1
  3. package/dist/formio.form.css +1 -0
  4. package/dist/formio.form.js +9 -9
  5. package/dist/formio.form.min.css +1 -1
  6. package/dist/formio.form.min.js +1 -1
  7. package/dist/formio.full.css +1 -0
  8. package/dist/formio.full.js +11 -11
  9. package/dist/formio.full.min.css +1 -1
  10. package/dist/formio.full.min.js +1 -1
  11. package/dist/formio.js +4 -4
  12. package/dist/formio.min.js +1 -1
  13. package/dist/formio.utils.js +5 -5
  14. package/dist/formio.utils.min.js +1 -1
  15. package/lib/cjs/PDFBuilder.d.ts +0 -1
  16. package/lib/cjs/PDFBuilder.js +8 -8
  17. package/lib/cjs/WebformBuilder.d.ts +1 -1
  18. package/lib/cjs/WebformBuilder.js +24 -23
  19. package/lib/cjs/components/_classes/nested/NestedComponent.js +1 -1
  20. package/lib/cjs/components/radio/Radio.d.ts +8 -0
  21. package/lib/cjs/components/radio/Radio.js +15 -5
  22. package/lib/cjs/components/select/Select.d.ts +1 -0
  23. package/lib/cjs/components/select/Select.js +18 -2
  24. package/lib/cjs/components/selectboxes/SelectBoxes.d.ts +6 -0
  25. package/lib/cjs/translations/en.d.ts +1 -0
  26. package/lib/cjs/translations/en.js +1 -1
  27. package/lib/cjs/utils/utils.js +10 -3
  28. package/lib/mjs/PDFBuilder.d.ts +0 -1
  29. package/lib/mjs/PDFBuilder.js +8 -8
  30. package/lib/mjs/WebformBuilder.d.ts +1 -1
  31. package/lib/mjs/WebformBuilder.js +25 -23
  32. package/lib/mjs/components/_classes/nested/NestedComponent.js +1 -1
  33. package/lib/mjs/components/radio/Radio.d.ts +8 -0
  34. package/lib/mjs/components/radio/Radio.js +15 -5
  35. package/lib/mjs/components/select/Select.d.ts +1 -0
  36. package/lib/mjs/components/select/Select.js +18 -2
  37. package/lib/mjs/components/selectboxes/SelectBoxes.d.ts +6 -0
  38. package/lib/mjs/translations/en.d.ts +1 -0
  39. package/lib/mjs/translations/en.js +1 -0
  40. package/lib/mjs/utils/utils.js +10 -2
  41. package/package.json +2 -2
@@ -51,6 +51,5 @@ export default class PDFBuilder extends WebformBuilder {
51
51
  onDropzoneDrop(e: any): boolean;
52
52
  dropEvent: any;
53
53
  onDragEnd(e: any): void;
54
- repeatablePathsComps: any[] | undefined;
55
54
  }
56
55
  import WebformBuilder from './WebformBuilder';
@@ -451,21 +451,21 @@ class PDFBuilder extends WebformBuilder_1.default {
451
451
  e.target.style.cursor = 'default';
452
452
  }
453
453
  highlightInvalidComponents() {
454
- const repeatablePathsComps = this.findComponentsWithRepeatablePaths();
454
+ const repeatablePaths = this.findRepeatablePaths();
455
455
  // update elements which path was duplicated if any pathes have been changed
456
- if (!lodash_1.default.isEqual(this.repeatablePathsComps, repeatablePathsComps)) {
457
- (0, utils_1.eachComponent)(this.webform.getComponents(), (comp) => {
458
- if (this.repeatablePathsComps.includes(comp.component)) {
456
+ if (!lodash_1.default.isEqual(this.repeatablePaths, repeatablePaths)) {
457
+ (0, utils_1.eachComponent)(this.webform.getComponents(), (comp, path) => {
458
+ if (this.repeatablePaths.includes(path)) {
459
459
  this.webform.postMessage({ name: 'updateElement', data: comp.component });
460
460
  }
461
461
  });
462
- this.repeatablePathsComps = repeatablePathsComps;
462
+ this.repeatablePaths = repeatablePaths;
463
463
  }
464
- if (!repeatablePathsComps.length) {
464
+ if (!repeatablePaths.length) {
465
465
  return;
466
466
  }
467
- (0, utils_1.eachComponent)(this.webform.getComponents(), (comp) => {
468
- if (this.repeatablePathsComps.includes(comp)) {
467
+ (0, utils_1.eachComponent)(this.webform.getComponents(), (comp, path) => {
468
+ if (this.repeatablePaths.includes(path)) {
469
469
  this.webform.postMessage({
470
470
  name: 'showBuilderErrors',
471
471
  data: {
@@ -78,7 +78,7 @@ export default class WebformBuilder extends Component {
78
78
  replaceDoubleQuotes(data: any, fieldsToRemoveDoubleQuotes?: any[]): any;
79
79
  updateComponent(component: any, changed: any): void;
80
80
  originalDefaultValue: any;
81
- findComponentsWithRepeatablePaths(): any[];
81
+ findRepeatablePaths(): any[];
82
82
  highlightInvalidComponents(): void;
83
83
  /**
84
84
  * Called when a new component is saved.
@@ -1125,40 +1125,41 @@ class WebformBuilder extends Component_1.default {
1125
1125
  // Called when we update a component.
1126
1126
  this.emit('updateComponent', component);
1127
1127
  }
1128
- findComponentsWithRepeatablePaths() {
1129
- const repeatablePaths = {};
1128
+ findRepeatablePaths() {
1129
+ const repeatablePaths = [];
1130
1130
  const keys = new Map();
1131
1131
  (0, utils_1.eachComponent)(this.form.components, (comp, path, components, parent, paths) => {
1132
- var _a, _b;
1133
- const isRadioCheckbox = comp.type === 'checkbox' && comp.inputType === 'radio';
1134
- if (keys.has(paths.dataPath)) {
1135
- const onlyRadioCheckboxes = ((_a = repeatablePaths[paths.dataPath]) === null || _a === void 0 ? void 0 : _a.onlyRadioCheckboxes) === false ? false : isRadioCheckbox;
1136
- repeatablePaths[paths.dataPath] = {
1137
- comps: [...(((_b = repeatablePaths[paths.dataPath]) === null || _b === void 0 ? void 0 : _b.comps) || []), keys.get(paths.dataPath), comp],
1138
- onlyRadioCheckboxes,
1139
- };
1140
- }
1141
- else {
1142
- keys.set(paths.dataPath, comp);
1132
+ const isLayout = (0, utils_1.componentInfo)(comp).layout;
1133
+ if (!isLayout) {
1134
+ if (keys.has(paths.dataPath)) {
1135
+ repeatablePaths.push(paths.dataPath);
1136
+ }
1137
+ else {
1138
+ keys.set(paths.dataPath, true);
1139
+ }
1143
1140
  }
1144
1141
  }, true);
1145
- const componentsWithRepeatablePaths = [];
1146
- Object.keys(repeatablePaths).forEach((path) => {
1147
- const { comps, onlyRadioCheckboxes } = repeatablePaths[path];
1148
- if (!onlyRadioCheckboxes) {
1149
- componentsWithRepeatablePaths.push(...comps);
1150
- }
1151
- });
1152
- return componentsWithRepeatablePaths;
1142
+ return repeatablePaths;
1153
1143
  }
1154
1144
  highlightInvalidComponents() {
1155
- const repeatablePathsComps = this.findComponentsWithRepeatablePaths();
1145
+ const repeatablePaths = this.findRepeatablePaths();
1156
1146
  let hasInvalidComponents = false;
1147
+ // Matches anything expect letters and '_' at the beginning of the key and anything except of letters, numbers,
1148
+ // '-', '.' and '_' in the rest of the key
1149
+ const badCharacters = /^[^A-Za-z_]+|[^A-Za-z0-9\-._]+/g;
1157
1150
  this.webform.everyComponent((comp) => {
1158
- if (repeatablePathsComps.includes(comp.component)) {
1151
+ const path = comp.path;
1152
+ if (repeatablePaths.includes(path)) {
1159
1153
  comp.setCustomValidity(this.t('apiKey', { key: comp.key }));
1160
1154
  hasInvalidComponents = true;
1161
1155
  }
1156
+ else if (comp.key.replace(badCharacters, '') === '') {
1157
+ comp.setCustomValidity(this.t('apiKeyNotValid', { key: comp.key }));
1158
+ hasInvalidComponents = true;
1159
+ }
1160
+ else {
1161
+ comp.setCustomValidity();
1162
+ }
1162
1163
  });
1163
1164
  this.emit('builderFormValidityChange', hasInvalidComponents);
1164
1165
  }
@@ -664,7 +664,7 @@ class NestedComponent extends Field_1.default {
664
664
  validationProcessor({ scope, data, row, instance, paths }, flags) {
665
665
  var _a;
666
666
  const { dirty } = flags;
667
- if (this.root.hasSubWizards && this.page !== this.root.page) {
667
+ if (this.root && this.root.hasSubWizards && this.page !== this.root.page) {
668
668
  instance = ((_a = this.componentsMap) === null || _a === void 0 ? void 0 : _a.hasOwnProperty(paths.dataPath))
669
669
  ? this.componentsMap[paths.dataPath]
670
670
  : this.getComponent(paths.dataPath);
@@ -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;
@@ -89,6 +89,7 @@ export default class SelectComponent extends ListComponent {
89
89
  disableInfiniteScroll(): void;
90
90
  set serverCount(value: any);
91
91
  get serverCount(): any;
92
+ shouldResetChoicesItems(items: any): boolean;
92
93
  setItems(items: any, fromSearch: any): void;
93
94
  selectItems: any;
94
95
  set downloadedResources(value: any);
@@ -355,6 +355,18 @@ class SelectComponent extends ListComponent_1.default {
355
355
  this.downloadedResources.serverCount = this.downloadedResources.length;
356
356
  this.serverCount = this.downloadedResources.length;
357
357
  }
358
+ shouldResetChoicesItems(items) {
359
+ if (this.choices._store.choices.length !== items.length) {
360
+ return true;
361
+ }
362
+ for (let item of items) {
363
+ const choicesItem = this.choices._store.choices.find((i) => i.label === item.label);
364
+ if (!choicesItem) {
365
+ return true;
366
+ }
367
+ }
368
+ return false;
369
+ }
358
370
  /* eslint-disable max-statements */
359
371
  setItems(items, fromSearch) {
360
372
  var _a, _b;
@@ -441,7 +453,7 @@ class SelectComponent extends ListComponent_1.default {
441
453
  this.addOption(itemValueAndLabel.value, itemValueAndLabel.label, {}, lodash_1.default.get(item, this.component.idPath, String(index)));
442
454
  });
443
455
  if (this.choices) {
444
- this.choices.setChoices(this.selectOptions, 'value', 'label', true);
456
+ this.choices.setChoices(this.selectOptions, 'value', 'label', true, true, !fromSearch && this.shouldResetChoicesItems(this.selectOptions));
445
457
  }
446
458
  else if (this.loading) {
447
459
  // Re-attach select input.
@@ -903,8 +915,9 @@ class SelectComponent extends ListComponent_1.default {
903
915
  });
904
916
  }
905
917
  // Add value options.
918
+ const value = this.undoValueTyping(this.dataValue);
906
919
  this.addValueOptions();
907
- this.setChoicesValue(this.dataValue);
920
+ this.setChoicesValue(value);
908
921
  if (this.isSelectResource && this.refs.addResource) {
909
922
  this.addEventListener(this.refs.addResource, 'click', (event) => {
910
923
  event.preventDefault();
@@ -1283,6 +1296,9 @@ class SelectComponent extends ListComponent_1.default {
1283
1296
  this.lazyLoadInit = true;
1284
1297
  const searchProperty = this.component.searchField || this.component.valueProperty;
1285
1298
  this.triggerUpdate(lodash_1.default.get(value.data || value, searchProperty, value), true);
1299
+ this.itemsLoaded.then(() => {
1300
+ this.setChoicesValue(value, hasPreviousValue, flags);
1301
+ });
1286
1302
  return changed;
1287
1303
  }
1288
1304
  // Add the value options.
@@ -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
  }
@@ -70,6 +70,7 @@ declare const _default: {
70
70
  reCaptchaTokenValidationError: string;
71
71
  reCaptchaTokenNotSpecifiedError: string;
72
72
  apiKey: string;
73
+ apiKeyNotValid: string;
73
74
  typeRemaining: string;
74
75
  typeCount: string;
75
76
  requiredDayField: string;
@@ -5,6 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const bootstrap_1 = __importDefault(require("@formio/bootstrap"));
8
- exports.default = Object.assign(Object.assign({}, (((_a = bootstrap_1.default === null || bootstrap_1.default === void 0 ? void 0 : bootstrap_1.default.translations) === null || _a === void 0 ? void 0 : _a.en) || {})), { unsavedRowsError: 'Please save all rows before proceeding.', invalidRowsError: 'Please correct invalid rows before proceeding.', invalidRowError: 'Invalid row. Please correct it or delete.', invalidOption: '{{field}} is an invalid value.', invalidDay: '{{field}} is not a valid day.', complete: 'Submission Complete', error: 'Please fix the following errors before submitting.', errorListHotkey: 'Press Ctrl + Alt + X to go back to the error list.', errorsListNavigationMessage: 'Click to navigate to the field with following error.', submitError: 'Please check the form and correct all errors before submitting.', required: '{{field}} is required', unique: '{{field}} must be unique', array: '{{field}} must be an array', array_nonempty: '{{field}} must be a non-empty array', nonarray: '{{field}} must not be an array', select: '{{field}} contains an invalid selection', pattern: '{{field}} does not match the pattern {{pattern}}', minLength: '{{field}} must have at least {{length}} characters.', maxLength: '{{field}} must have no more than {{length}} characters.', minWords: '{{field}} must have at least {{length}} words.', maxWords: '{{field}} must have no more than {{length}} words.', min: '{{field}} cannot be less than {{min}}.', max: '{{field}} cannot be greater than {{max}}.', maxDate: '{{field}} should not contain date after {{maxDate}}', minDate: '{{field}} should not contain date before {{minDate}}', maxYear: '{{field}} should not contain year greater than {{maxYear}}', minYear: '{{field}} should not contain year less than {{minYear}}', minSelectedCount: 'You must select at least {{minCount}} items', maxSelectedCount: 'You may only select up to {{maxCount}} items', invalid_email: '{{field}} must be a valid email.', invalid_url: '{{field}} must be a valid url.', invalid_regex: '{{field}} does not match the pattern {{regex}}.', invalid_date: '{{field}} is not a valid date.', invalid_day: '{{field}} is not a valid day.', invalidValueProperty: 'Invalid Value Property', mask: '{{field}} does not match the mask.', valueIsNotAvailable: '{{ field }} is an invalid value.', stripe: '{{stripe}}', month: 'Month', day: 'Day', year: 'Year', january: 'January', february: 'February', march: 'March', april: 'April', may: 'May', june: 'June', july: 'July', august: 'August', september: 'September', october: 'October', november: 'November', december: 'December', next: 'Next', previous: 'Previous', cancel: 'Cancel', submit: 'Submit Form', confirmCancel: 'Are you sure you want to cancel?', saveDraftInstanceError: 'Cannot save draft because there is no formio instance.', saveDraftAuthError: 'Cannot save draft unless a user is authenticated.', restoreDraftInstanceError: 'Cannot restore draft because there is no formio instance.', saveDraftError: 'Unable to save draft.', restoreDraftError: 'Unable to restore draft.', time: 'Invalid time', cancelButtonAriaLabel: 'Cancel button. Click to reset the form', previousButtonAriaLabel: 'Previous button. Click to go back to the previous tab', nextButtonAriaLabel: 'Next button. Click to go to the next tab', submitButtonAriaLabel: 'Submit Form button. Click to submit the form', reCaptchaTokenValidationError: 'ReCAPTCHA: Token validation error', reCaptchaTokenNotSpecifiedError: 'ReCAPTCHA: Token is not specified in submission', apiKey: 'API Key is not unique: {{key}}', typeRemaining: '{{ remaining }} {{ type }} remaining.', typeCount: '{{ count }} {{ type }}', requiredDayField: '{{ field }} is required', requiredDayEmpty: '{{ field }} is required', requiredMonthField: '{{ field }} is required', requiredYearField: '{{ field }} is required', formNotReady: 'Form not ready. Use form.ready promise', noFormElement: 'No DOM element for form.', notUniqueKey: 'API Key is not unique', newFormSchema: 'Form schema is for a newer version, please upgrade your renderer. Some functionality may not work.', missingUrl: 'Missing URL argument', urlNotAttachedToBtn: 'You should add a URL to this button.', loadingProjectSettingsError: 'Could not load project settings', sessionStorageSupportError: 'Session storage is not supported in this browser.', builderUniqueError: `You cannot add more than one {{componentKeyOrTitle}} component to one page.`, pageNotFound: 'Page not found', noDragInfoError: 'There is no Drag Info available for either dragged or sibling element', addonSupportTypeError: 'Addon {{label}} does not support component of type {{type}}', setPathError: 'Should not be setting the path of a component.', calculatedPathDeprecation: 'component.calculatedPath was deprecated, use component.path instead.', unknownTemplate: 'Unknown template: {{name}}', unknownComponent: 'Unknown component: {{type}}', renderTemplateFunctionDeprecation: `Form.io 'render' template function is deprecated.
8
+ exports.default = Object.assign(Object.assign({}, (((_a = bootstrap_1.default === null || bootstrap_1.default === void 0 ? void 0 : bootstrap_1.default.translations) === null || _a === void 0 ? void 0 : _a.en) || {})), { unsavedRowsError: 'Please save all rows before proceeding.', invalidRowsError: 'Please correct invalid rows before proceeding.', invalidRowError: 'Invalid row. Please correct it or delete.', invalidOption: '{{field}} is an invalid value.', invalidDay: '{{field}} is not a valid day.', complete: 'Submission Complete', error: 'Please fix the following errors before submitting.', errorListHotkey: 'Press Ctrl + Alt + X to go back to the error list.', errorsListNavigationMessage: 'Click to navigate to the field with following error.', submitError: 'Please check the form and correct all errors before submitting.', required: '{{field}} is required', unique: '{{field}} must be unique', array: '{{field}} must be an array', array_nonempty: '{{field}} must be a non-empty array', nonarray: '{{field}} must not be an array', select: '{{field}} contains an invalid selection', pattern: '{{field}} does not match the pattern {{pattern}}', minLength: '{{field}} must have at least {{length}} characters.', maxLength: '{{field}} must have no more than {{length}} characters.', minWords: '{{field}} must have at least {{length}} words.', maxWords: '{{field}} must have no more than {{length}} words.', min: '{{field}} cannot be less than {{min}}.', max: '{{field}} cannot be greater than {{max}}.', maxDate: '{{field}} should not contain date after {{maxDate}}', minDate: '{{field}} should not contain date before {{minDate}}', maxYear: '{{field}} should not contain year greater than {{maxYear}}', minYear: '{{field}} should not contain year less than {{minYear}}', minSelectedCount: 'You must select at least {{minCount}} items', maxSelectedCount: 'You may only select up to {{maxCount}} items', invalid_email: '{{field}} must be a valid email.', invalid_url: '{{field}} must be a valid url.', invalid_regex: '{{field}} does not match the pattern {{regex}}.', invalid_date: '{{field}} is not a valid date.', invalid_day: '{{field}} is not a valid day.', invalidValueProperty: 'Invalid Value Property', mask: '{{field}} does not match the mask.', valueIsNotAvailable: '{{ field }} is an invalid value.', stripe: '{{stripe}}', month: 'Month', day: 'Day', year: 'Year', january: 'January', february: 'February', march: 'March', april: 'April', may: 'May', june: 'June', july: 'July', august: 'August', september: 'September', october: 'October', november: 'November', december: 'December', next: 'Next', previous: 'Previous', cancel: 'Cancel', submit: 'Submit Form', confirmCancel: 'Are you sure you want to cancel?', saveDraftInstanceError: 'Cannot save draft because there is no formio instance.', saveDraftAuthError: 'Cannot save draft unless a user is authenticated.', restoreDraftInstanceError: 'Cannot restore draft because there is no formio instance.', saveDraftError: 'Unable to save draft.', restoreDraftError: 'Unable to restore draft.', time: 'Invalid time', cancelButtonAriaLabel: 'Cancel button. Click to reset the form', previousButtonAriaLabel: 'Previous button. Click to go back to the previous tab', nextButtonAriaLabel: 'Next button. Click to go to the next tab', submitButtonAriaLabel: 'Submit Form button. Click to submit the form', reCaptchaTokenValidationError: 'ReCAPTCHA: Token validation error', reCaptchaTokenNotSpecifiedError: 'ReCAPTCHA: Token is not specified in submission', apiKey: 'API Key is not unique: {{key}}', apiKeyNotValid: 'API Key is not valid: {{key}}', typeRemaining: '{{ remaining }} {{ type }} remaining.', typeCount: '{{ count }} {{ type }}', requiredDayField: '{{ field }} is required', requiredDayEmpty: '{{ field }} is required', requiredMonthField: '{{ field }} is required', requiredYearField: '{{ field }} is required', formNotReady: 'Form not ready. Use form.ready promise', noFormElement: 'No DOM element for form.', notUniqueKey: 'API Key is not unique', newFormSchema: 'Form schema is for a newer version, please upgrade your renderer. Some functionality may not work.', missingUrl: 'Missing URL argument', urlNotAttachedToBtn: 'You should add a URL to this button.', loadingProjectSettingsError: 'Could not load project settings', sessionStorageSupportError: 'Session storage is not supported in this browser.', builderUniqueError: `You cannot add more than one {{componentKeyOrTitle}} component to one page.`, pageNotFound: 'Page not found', noDragInfoError: 'There is no Drag Info available for either dragged or sibling element', addonSupportTypeError: 'Addon {{label}} does not support component of type {{type}}', setPathError: 'Should not be setting the path of a component.', calculatedPathDeprecation: 'component.calculatedPath was deprecated, use component.path instead.', unknownTemplate: 'Unknown template: {{name}}', unknownComponent: 'Unknown component: {{type}}', renderTemplateFunctionDeprecation: `Form.io 'render' template function is deprecated.
9
9
  If you need to render template (template A) inside of another template (template B),
10
10
  pass pre-compiled template A (use this.renderTemplate('template_A_name') as template context variable for template B`, whenReadyDeprecation: 'The whenReady() method has been deprecated. Please use the dataReady property instead.', loadResourcesError: 'Unable to load resources for {{componentKey}}', noSelectDataConfiguration: 'Select component {{componentKey}} does not have data configuration.', indexedDBSupportError: "Your browser doesn't support current version of indexedDB", caretPositionSavingError: 'An error occurred while trying to save caret position', iteratableRowsError: 'Getter #iteratableRows() is not implemented', checkRowDeprecation: 'Deprecation Warning: checkRow method has been replaced with processRow', noOAuthBtn: 'You must add the OAuth button to a form for it to function properly', noOAuthConfiguration: 'OAuth not configured. You must configure oauth for your project before it will work.', oAuthErrorsTitle: 'The Following Error Has Occured', noOAuthFormUrl: 'You must attach a Form API url to your form in order to use OAuth buttons.', oAuthStateError: 'OAuth state does not match. Please try logging in again.', componentInvalidRowValidation: 'Invalid row validation for {{componentKey}}', videoPlayerNotFound: 'Video player not found in template.', synchronizationFailed: 'Synchronization is failed', fileWithDuplicatedNameInProgress: 'File with the same name is already being uploaded', fileWithDuplicatedNameLoaded: 'File with the same name is already uploaded', nestedForm: 'Nested form', noDataProvided: 'No data provided', subformSubmissionLoadingError: 'Unable to load subform submission {{submissionId}}:', noDelimiterSet: 'In order for thousands separator to work properly, you must set the delimiter to true in the component json', noSiteKey: 'There is no Site Key specified in settings in form JSON', failedToNormalize: 'Failed to normalize value', failedToCompareItems: 'Error while comparing items', editorFocusError: 'An editor did not initialize properly when trying to focus:', quillImageUploadFailed: 'Quill image upload failed', noFilesSelected: 'No files selected', needConfigurationForQuill: 'The WYSIWYG settings are configured for CKEditor. For this renderer, you will need to use configurations for the Quill Editor. See https://quilljs.com/docs/configuration for more information.', waitPdfConverting: 'Converting PDF. Please wait.', uploading: 'Uploading', pasteBelow: 'Paste below', copy: 'Copy', move: 'Move', edit: 'Edit', editJson: 'Edit JSON', remove: 'Remove', clickToSetValue: 'Click to set value', words: 'words', characters: 'characters', addAnother: 'Add Another', yes: 'Yes', no: 'No', wantToClearData: 'Do you want to clear data?', yesDelete: 'Yes, delete it', waitFileProcessing: 'Processing file. Please wait...', wrongFileType: 'File is the wrong type; it must be {{ pattern }}', fileTooSmall: 'File is too small; it must be at least {{ size }}', fileTooBig: 'File is too big; it must be at most {{ size }}', noFileService: 'File Service not provided.', fileProcessingFailed: 'File processing has been failed.', readyForUpload: 'Ready to be uploaded into storage', readyForRemovingFromStorage: 'Ready to be removed from storage', preparingFileToRemove: 'Preparing file to remove', succefullyRemoved: 'Succefully removed', succefullyUploaded: 'Succefully uploaded', maxSelectItems: 'You may only select up to {{maxCount}} items', minSelectItems: 'You must select at least {{minCount}} items', clickToSign: 'Click to Sign', surveyQuestion: 'Question', surveyQuestionValue: 'Value', success: 'Success', noResultsFound: 'No results found', noChoices: 'No choices to choose from', typeToSearch: 'Type to search', loading: 'Loading' });
@@ -209,13 +209,20 @@ function checkSimpleConditional(component, condition, row, data, instance) {
209
209
  return true;
210
210
  }
211
211
  const conditionsResult = lodash_1.default.map(conditions, (cond) => {
212
- var _a, _b;
213
212
  const { value: comparedValue, operator, component: conditionComponentPath } = cond;
214
213
  if (!conditionComponentPath) {
215
214
  return true;
216
215
  }
217
216
  const splittedConditionPath = conditionComponentPath.split('.');
218
- const conditionalPaths = ((_a = instance === null || instance === void 0 ? void 0 : instance.parent) === null || _a === void 0 ? void 0 : _a.type) === 'datagrid' || ((_b = instance === null || instance === void 0 ? void 0 : instance.parent) === null || _b === void 0 ? void 0 : _b.type) === 'editgrid' ? [] : getConditionalPathsRecursive(splittedConditionPath, data);
217
+ const checkParentTypeInTree = (instance, componentType) => {
218
+ if (!(instance === null || instance === void 0 ? void 0 : instance.parent)) {
219
+ return false;
220
+ }
221
+ return (instance === null || instance === void 0 ? void 0 : instance.parent.type) === componentType || checkParentTypeInTree(instance.parent, componentType);
222
+ };
223
+ const conditionalPaths = checkParentTypeInTree(instance, 'datagrid') || checkParentTypeInTree(instance, 'editgrid')
224
+ ? []
225
+ : getConditionalPathsRecursive(splittedConditionPath, data);
219
226
  if (conditionalPaths.length > 0) {
220
227
  return conditionalPaths.map((path) => {
221
228
  const value = getComponentActualValue(path, data, row);
@@ -334,7 +341,7 @@ function getRow(component, row, instance, conditional) {
334
341
  }
335
342
  const dataParent = getDataParentComponent(instance);
336
343
  if (dataParent) {
337
- const parentPath = (_a = dataParent.paths) === null || _a === void 0 ? void 0 : _a.localDataPath;
344
+ const parentPath = (_a = dataParent.paths) === null || _a === void 0 ? void 0 : _a.localPath;
338
345
  const isTriggerCondtionComponentPath = condition.when || !condition.conditions
339
346
  ? (_b = condition.when) === null || _b === void 0 ? void 0 : _b.startsWith((_c = dataParent.paths) === null || _c === void 0 ? void 0 : _c.localPath)
340
347
  : lodash_1.default.some(condition.conditions, cond => { var _a; return cond.component.startsWith((_a = dataParent.paths) === null || _a === void 0 ? void 0 : _a.localPath); });
@@ -51,6 +51,5 @@ export default class PDFBuilder extends WebformBuilder {
51
51
  onDropzoneDrop(e: any): boolean;
52
52
  dropEvent: any;
53
53
  onDragEnd(e: any): void;
54
- repeatablePathsComps: any[] | undefined;
55
54
  }
56
55
  import WebformBuilder from './WebformBuilder';
@@ -444,21 +444,21 @@ export default class PDFBuilder extends WebformBuilder {
444
444
  e.target.style.cursor = 'default';
445
445
  }
446
446
  highlightInvalidComponents() {
447
- const repeatablePathsComps = this.findComponentsWithRepeatablePaths();
447
+ const repeatablePaths = this.findRepeatablePaths();
448
448
  // update elements which path was duplicated if any pathes have been changed
449
- if (!_.isEqual(this.repeatablePathsComps, repeatablePathsComps)) {
450
- eachComponent(this.webform.getComponents(), (comp) => {
451
- if (this.repeatablePathsComps.includes(comp.component)) {
449
+ if (!_.isEqual(this.repeatablePaths, repeatablePaths)) {
450
+ eachComponent(this.webform.getComponents(), (comp, path) => {
451
+ if (this.repeatablePaths.includes(path)) {
452
452
  this.webform.postMessage({ name: 'updateElement', data: comp.component });
453
453
  }
454
454
  });
455
- this.repeatablePathsComps = repeatablePathsComps;
455
+ this.repeatablePaths = repeatablePaths;
456
456
  }
457
- if (!repeatablePathsComps.length) {
457
+ if (!repeatablePaths.length) {
458
458
  return;
459
459
  }
460
- eachComponent(this.webform.getComponents(), (comp) => {
461
- if (this.repeatablePathsComps.includes(comp)) {
460
+ eachComponent(this.webform.getComponents(), (comp, path) => {
461
+ if (this.repeatablePaths.includes(path)) {
462
462
  this.webform.postMessage({
463
463
  name: 'showBuilderErrors',
464
464
  data: {
@@ -78,7 +78,7 @@ export default class WebformBuilder extends Component {
78
78
  replaceDoubleQuotes(data: any, fieldsToRemoveDoubleQuotes?: any[]): any;
79
79
  updateComponent(component: any, changed: any): void;
80
80
  originalDefaultValue: any;
81
- findComponentsWithRepeatablePaths(): any[];
81
+ findRepeatablePaths(): any[];
82
82
  highlightInvalidComponents(): void;
83
83
  /**
84
84
  * Called when a new component is saved.
@@ -3,7 +3,7 @@ import Component from './components/_classes/component/Component';
3
3
  import tippy from 'tippy.js';
4
4
  import Components from './components/Components';
5
5
  import { Formio } from './Formio';
6
- import { fastCloneDeep, bootstrapVersion, getArrayFromComponentPath, getStringFromComponentPath, eachComponent, getComponent, } from './utils';
6
+ import { fastCloneDeep, bootstrapVersion, getArrayFromComponentPath, getStringFromComponentPath, eachComponent, getComponent, componentInfo } from './utils';
7
7
  import BuilderUtils from './utils/builder';
8
8
  import _ from 'lodash';
9
9
  import autoScroll from 'dom-autoscroller';
@@ -1108,39 +1108,41 @@ export default class WebformBuilder extends Component {
1108
1108
  // Called when we update a component.
1109
1109
  this.emit('updateComponent', component);
1110
1110
  }
1111
- findComponentsWithRepeatablePaths() {
1112
- const repeatablePaths = {};
1111
+ findRepeatablePaths() {
1112
+ const repeatablePaths = [];
1113
1113
  const keys = new Map();
1114
1114
  eachComponent(this.form.components, (comp, path, components, parent, paths) => {
1115
- const isRadioCheckbox = comp.type === 'checkbox' && comp.inputType === 'radio';
1116
- if (keys.has(paths.dataPath)) {
1117
- const onlyRadioCheckboxes = repeatablePaths[paths.dataPath]?.onlyRadioCheckboxes === false ? false : isRadioCheckbox;
1118
- repeatablePaths[paths.dataPath] = {
1119
- comps: [...(repeatablePaths[paths.dataPath]?.comps || []), keys.get(paths.dataPath), comp],
1120
- onlyRadioCheckboxes,
1121
- };
1122
- }
1123
- else {
1124
- keys.set(paths.dataPath, comp);
1115
+ const isLayout = componentInfo(comp).layout;
1116
+ if (!isLayout) {
1117
+ if (keys.has(paths.dataPath)) {
1118
+ repeatablePaths.push(paths.dataPath);
1119
+ }
1120
+ else {
1121
+ keys.set(paths.dataPath, true);
1122
+ }
1125
1123
  }
1126
1124
  }, true);
1127
- const componentsWithRepeatablePaths = [];
1128
- Object.keys(repeatablePaths).forEach((path) => {
1129
- const { comps, onlyRadioCheckboxes } = repeatablePaths[path];
1130
- if (!onlyRadioCheckboxes) {
1131
- componentsWithRepeatablePaths.push(...comps);
1132
- }
1133
- });
1134
- return componentsWithRepeatablePaths;
1125
+ return repeatablePaths;
1135
1126
  }
1136
1127
  highlightInvalidComponents() {
1137
- const repeatablePathsComps = this.findComponentsWithRepeatablePaths();
1128
+ const repeatablePaths = this.findRepeatablePaths();
1138
1129
  let hasInvalidComponents = false;
1130
+ // Matches anything expect letters and '_' at the beginning of the key and anything except of letters, numbers,
1131
+ // '-', '.' and '_' in the rest of the key
1132
+ const badCharacters = /^[^A-Za-z_]+|[^A-Za-z0-9\-._]+/g;
1139
1133
  this.webform.everyComponent((comp) => {
1140
- if (repeatablePathsComps.includes(comp.component)) {
1134
+ const path = comp.path;
1135
+ if (repeatablePaths.includes(path)) {
1141
1136
  comp.setCustomValidity(this.t('apiKey', { key: comp.key }));
1142
1137
  hasInvalidComponents = true;
1143
1138
  }
1139
+ else if (comp.key.replace(badCharacters, '') === '') {
1140
+ comp.setCustomValidity(this.t('apiKeyNotValid', { key: comp.key }));
1141
+ hasInvalidComponents = true;
1142
+ }
1143
+ else {
1144
+ comp.setCustomValidity();
1145
+ }
1144
1146
  });
1145
1147
  this.emit('builderFormValidityChange', hasInvalidComponents);
1146
1148
  }
@@ -659,7 +659,7 @@ export default class NestedComponent extends Field {
659
659
  }
660
660
  validationProcessor({ scope, data, row, instance, paths }, flags) {
661
661
  const { dirty } = flags;
662
- if (this.root.hasSubWizards && this.page !== this.root.page) {
662
+ if (this.root && this.root.hasSubWizards && this.page !== this.root.page) {
663
663
  instance = this.componentsMap?.hasOwnProperty(paths.dataPath)
664
664
  ? this.componentsMap[paths.dataPath]
665
665
  : this.getComponent(paths.dataPath);
@@ -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
  }
@@ -89,6 +89,7 @@ export default class SelectComponent extends ListComponent {
89
89
  disableInfiniteScroll(): void;
90
90
  set serverCount(value: any);
91
91
  get serverCount(): any;
92
+ shouldResetChoicesItems(items: any): boolean;
92
93
  setItems(items: any, fromSearch: any): void;
93
94
  selectItems: any;
94
95
  set downloadedResources(value: any);
@@ -359,6 +359,18 @@ export default class SelectComponent extends ListComponent {
359
359
  this.downloadedResources.serverCount = this.downloadedResources.length;
360
360
  this.serverCount = this.downloadedResources.length;
361
361
  }
362
+ shouldResetChoicesItems(items) {
363
+ if (this.choices._store.choices.length !== items.length) {
364
+ return true;
365
+ }
366
+ for (let item of items) {
367
+ const choicesItem = this.choices._store.choices.find((i) => i.label === item.label);
368
+ if (!choicesItem) {
369
+ return true;
370
+ }
371
+ }
372
+ return false;
373
+ }
362
374
  /* eslint-disable max-statements */
363
375
  setItems(items, fromSearch) {
364
376
  this.selectItems = items;
@@ -444,7 +456,7 @@ export default class SelectComponent extends ListComponent {
444
456
  this.addOption(itemValueAndLabel.value, itemValueAndLabel.label, {}, _.get(item, this.component.idPath, String(index)));
445
457
  });
446
458
  if (this.choices) {
447
- this.choices.setChoices(this.selectOptions, 'value', 'label', true);
459
+ this.choices.setChoices(this.selectOptions, 'value', 'label', true, true, !fromSearch && this.shouldResetChoicesItems(this.selectOptions));
448
460
  }
449
461
  else if (this.loading) {
450
462
  // Re-attach select input.
@@ -935,8 +947,9 @@ export default class SelectComponent extends ListComponent {
935
947
  });
936
948
  }
937
949
  // Add value options.
950
+ const value = this.undoValueTyping(this.dataValue);
938
951
  this.addValueOptions();
939
- this.setChoicesValue(this.dataValue);
952
+ this.setChoicesValue(value);
940
953
  if (this.isSelectResource && this.refs.addResource) {
941
954
  this.addEventListener(this.refs.addResource, 'click', (event) => {
942
955
  event.preventDefault();
@@ -1312,6 +1325,9 @@ export default class SelectComponent extends ListComponent {
1312
1325
  this.lazyLoadInit = true;
1313
1326
  const searchProperty = this.component.searchField || this.component.valueProperty;
1314
1327
  this.triggerUpdate(_.get(value.data || value, searchProperty, value), true);
1328
+ this.itemsLoaded.then(() => {
1329
+ this.setChoicesValue(value, hasPreviousValue, flags);
1330
+ });
1315
1331
  return changed;
1316
1332
  }
1317
1333
  // Add the value options.
@@ -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
  }