@formio/js 5.0.0-dev.5633.3b83d8c → 5.0.0-dev.5633.3e0990b

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.
@@ -357,11 +357,12 @@ declare class Webform extends NestedDataComponent {
357
357
  */
358
358
  get submission(): Object;
359
359
  /**
360
- * @param submission
361
- * @param flags
362
- * @return {void}
363
- */
364
- onSetSubmission(submission: any, flags?: {}): void;
360
+ * Sets the submission value
361
+ * @param {object|null|undefined} submission - The submission to set.
362
+ * @param {object|null|undefined} flags - Any flags to apply when setting the submission.
363
+ * @return {void}
364
+ */
365
+ onSetSubmission(submission: object | null | undefined, flags?: object | null | undefined): void;
365
366
  /**
366
367
  * Sets a submission and returns the promise when it is ready.
367
368
  * @param submission
@@ -717,10 +717,11 @@ class Webform extends NestedDataComponent_1.default {
717
717
  this.setSubmission(submission);
718
718
  }
719
719
  /**
720
- * @param submission
721
- * @param flags
722
- * @return {void}
723
- */
720
+ * Sets the submission value
721
+ * @param {object|null|undefined} submission - The submission to set.
722
+ * @param {object|null|undefined} flags - Any flags to apply when setting the submission.
723
+ * @return {void}
724
+ */
724
725
  onSetSubmission(submission, flags = {}) {
725
726
  this.submissionSet = true;
726
727
  this.triggerChange(flags);
@@ -795,7 +796,8 @@ class Webform extends NestedDataComponent_1.default {
795
796
  formio.loadSubmissions({
796
797
  params: {
797
798
  state: 'draft',
798
- owner: userId
799
+ owner: userId,
800
+ sort: '-created'
799
801
  }
800
802
  }).then(submissions => {
801
803
  if (submissions.length > 0 && !this.options.skipDraftRestore) {
@@ -986,8 +986,14 @@ class WebformBuilder extends Component_1.default {
986
986
  else if (parent.formioComponent && parent.formioComponent.removeChildComponent) {
987
987
  parent.formioComponent.removeChildComponent(component);
988
988
  }
989
- if (component.input && componentInstance && componentInstance.parent) {
990
- lodash_1.default.unset(componentInstance._data, componentInstance.key);
989
+ if (component.input && componentInstance && parent.formioComponent) {
990
+ const parentDefaultValue = lodash_1.default.get(parent.formioComponent, 'component.defaultValue', null);
991
+ if (Array.isArray(parentDefaultValue)) {
992
+ parentDefaultValue.forEach(v => lodash_1.default.unset(v, componentInstance.key));
993
+ }
994
+ else if (typeof parentDefaultValue === 'object') {
995
+ lodash_1.default.unset(parentDefaultValue, componentInstance.key);
996
+ }
991
997
  }
992
998
  const rebuild = parent.formioComponent.rebuild() || Promise.resolve();
993
999
  rebuild.then(() => {
@@ -327,12 +327,23 @@ declare class Component extends Element {
327
327
  */
328
328
  loadRefs(element: HTMLElement, refs: object, referenceAttributeName?: string | undefined): void;
329
329
  setOpenModalElement(template: any): void;
330
- renderModalPreview(ctx: any): any;
331
- getModalPreviewTemplate(): any;
330
+ /**
331
+ * Renders a modal preview template and returns the markup as a string
332
+ * @param {object|null|undefined} ctx - The rendering context
333
+ * @return {string} - The modal preview markup
334
+ */
335
+ renderModalPreview(ctx: object | null | undefined): string;
336
+ getModalPreviewTemplate(): string;
332
337
  build(element: any): Promise<void>;
333
338
  get hasModalSaveButton(): boolean;
334
339
  render(children?: string, topLevel?: boolean): any;
335
- createTooltip(tooltipEl: any, settings?: {}): import("tippy.js").Instance<import("tippy.js").Props>[];
340
+ /**
341
+ * Creates the tooltip instance using tippy.js and returns it
342
+ * @param {HTMLElement} tooltipEl - HTML element to attach the tooltip
343
+ * @param {object|null|undefined} settings - tippy.js options
344
+ * @return {import('tippy.js').Tippy} - tippy.js instance
345
+ */
346
+ createTooltip(tooltipEl: HTMLElement, settings?: object | null | undefined): import('tippy.js').Tippy;
336
347
  attachTooltips(toolTipsRefs: any): void;
337
348
  createComponentModal(element: any, modalShouldBeOpened: any, currentValue: any): ComponentModal;
338
349
  attach(element: any): Promise<void>;
@@ -1029,6 +1029,11 @@ class Component extends Element_1.default {
1029
1029
  setOpenModalElement(template) {
1030
1030
  this.componentModal.setOpenModalElement(template || this.getModalPreviewTemplate());
1031
1031
  }
1032
+ /**
1033
+ * Renders a modal preview template and returns the markup as a string
1034
+ * @param {object|null|undefined} ctx - The rendering context
1035
+ * @return {string} - The modal preview markup
1036
+ */
1032
1037
  renderModalPreview(ctx) {
1033
1038
  return this.renderTemplate('modalPreview', ctx || {});
1034
1039
  }
@@ -1077,6 +1082,12 @@ class Component extends Element_1.default {
1077
1082
  }, topLevel);
1078
1083
  }
1079
1084
  }
1085
+ /**
1086
+ * Creates the tooltip instance using tippy.js and returns it
1087
+ * @param {HTMLElement} tooltipEl - HTML element to attach the tooltip
1088
+ * @param {object|null|undefined} settings - tippy.js options
1089
+ * @return {import('tippy.js').Tippy} - tippy.js instance
1090
+ */
1080
1091
  createTooltip(tooltipEl, settings = {}) {
1081
1092
  const tooltipAttribute = tooltipEl.getAttribute('data-tooltip');
1082
1093
  const tooltipDataTitle = tooltipEl.getAttribute('data-title');
@@ -1849,9 +1860,6 @@ class Component extends Element_1.default {
1849
1860
  messages = lodash_1.default.uniqBy(messages, message => message.message);
1850
1861
  if (this.refs.messageContainer) {
1851
1862
  this.setContent(this.refs.messageContainer, messages.map((message) => {
1852
- if (message.message && typeof message.message === 'string') {
1853
- message.message = message.message.replaceAll('<', '&lt;').replaceAll('>', '&gt;');
1854
- }
1855
1863
  return this.renderTemplate('message', Object.assign({}, message));
1856
1864
  }).join(''));
1857
1865
  }
@@ -2561,7 +2569,7 @@ class Component extends Element_1.default {
2561
2569
  }
2562
2570
  this.calculatedValue = (0, utils_1.fastCloneDeep)(calculatedValue);
2563
2571
  if (changed) {
2564
- if (!flags.noPristineChangeOnModified) {
2572
+ if (!flags.noPristineChangeOnModified && this.root.initialized) {
2565
2573
  this.pristine = false;
2566
2574
  }
2567
2575
  flags.triggeredComponentId = this.id;
@@ -79,7 +79,13 @@ export default class FormComponent extends Component {
79
79
  isHidden(): boolean;
80
80
  setValue(submission: any, flags?: {}): boolean;
81
81
  setSubFormValue(submission: any, flags: any): void;
82
- onSetSubFormValue(submission: any, flags: any): void;
82
+ /**
83
+ * Sets the subform value
84
+ * @param {object|null|undefined} submission - The submission to set.
85
+ * @param {object|null|undefined} flags - Any flags to apply when setting the submission.
86
+ * @return {void}
87
+ */
88
+ onSetSubFormValue(submission: object | null | undefined, flags: object | null | undefined): void;
83
89
  areAllComponentsEmpty(data: any): boolean;
84
90
  updateSubFormVisibility(): void;
85
91
  /**
@@ -431,7 +431,7 @@ class FormComponent extends Component_1.default {
431
431
  * Load the subform.
432
432
  */
433
433
  loadSubForm(fromAttach) {
434
- var _a, _b, _c;
434
+ var _a, _b, _c, _d, _e;
435
435
  if (this.builderMode || this.isHidden() || (this.isSubFormLazyLoad() && !fromAttach)) {
436
436
  return Promise.resolve();
437
437
  }
@@ -445,7 +445,7 @@ class FormComponent extends Component_1.default {
445
445
  }
446
446
  else if (this.formSrc) {
447
447
  this.subFormLoading = true;
448
- const options = ((_b = this.root.formio) === null || _b === void 0 ? void 0 : _b.base) && ((_c = this.root.formio) === null || _c === void 0 ? void 0 : _c.projectUrl)
448
+ const options = ((_c = (_b = this.root) === null || _b === void 0 ? void 0 : _b.formio) === null || _c === void 0 ? void 0 : _c.base) && ((_e = (_d = this.root) === null || _d === void 0 ? void 0 : _d.formio) === null || _e === void 0 ? void 0 : _e.projectUrl)
449
449
  ? {
450
450
  base: this.root.formio.base,
451
451
  project: this.root.formio.projectUrl,
@@ -625,15 +625,16 @@ class FormComponent extends Component_1.default {
625
625
  return changed;
626
626
  }
627
627
  setSubFormValue(submission, flags) {
628
- var _a, _b;
628
+ var _a, _b, _c, _d;
629
629
  const shouldLoadSubmissionById = submission
630
630
  && submission._id
631
631
  && this.subForm.formio
632
632
  && lodash_1.default.isEmpty(submission.data);
633
- if (shouldLoadSubmissionById) {
633
+ const shouldLoadDraftById = this.options.saveDraft && lodash_1.default.isEmpty(submission.data) && lodash_1.default.get(this.subForm, 'submission._id');
634
+ if (shouldLoadSubmissionById || shouldLoadDraftById) {
634
635
  const formId = submission.form || this.formObj.form || this.component.form;
635
- const submissionUrl = `${this.subForm.formio.formsUrl}/${formId}/submission/${submission._id}`;
636
- const options = ((_a = this.root.formio) === null || _a === void 0 ? void 0 : _a.base) && ((_b = this.root.formio) === null || _b === void 0 ? void 0 : _b.projectUrl)
636
+ const submissionUrl = `${this.subForm.formio.formsUrl}/${formId}/submission/${submission._id || this.subForm.submission._id}`;
637
+ const options = ((_b = (_a = this.root) === null || _a === void 0 ? void 0 : _a.formio) === null || _b === void 0 ? void 0 : _b.base) && ((_d = (_c = this.root) === null || _c === void 0 ? void 0 : _c.formio) === null || _d === void 0 ? void 0 : _d.projectUrl)
637
638
  ? {
638
639
  base: this.root.formio.base,
639
640
  project: this.root.formio.projectUrl,
@@ -648,6 +649,12 @@ class FormComponent extends Component_1.default {
648
649
  this.onSetSubFormValue(submission, flags);
649
650
  }
650
651
  }
652
+ /**
653
+ * Sets the subform value
654
+ * @param {object|null|undefined} submission - The submission to set.
655
+ * @param {object|null|undefined} flags - Any flags to apply when setting the submission.
656
+ * @return {void}
657
+ */
651
658
  onSetSubFormValue(submission, flags) {
652
659
  this.subForm.setValue(submission, flags);
653
660
  }
@@ -1526,7 +1526,7 @@ class SelectComponent extends ListComponent_1.default {
1526
1526
  const getTemplateValue = (v) => {
1527
1527
  const itemTemplate = this.itemTemplate(v);
1528
1528
  return options.csv && itemTemplate
1529
- ? (0, utils_1.unescapeHTML)(itemTemplate)
1529
+ ? (0, utils_1.removeHTML)(itemTemplate)
1530
1530
  : itemTemplate;
1531
1531
  };
1532
1532
  if (Array.isArray(value)) {
@@ -107,6 +107,12 @@ export function checkCondition(component: any, row: any, data: any, form: any, i
107
107
  */
108
108
  export function checkTrigger(component: any, trigger: any, row: any, data: any, form: any, instance: any): mixed;
109
109
  export function setActionProperty(component: any, action: any, result: any, row: any, data: any, instance: any): any;
110
+ /**
111
+ * Removes HTML tags from string e.g. <div>Hello World</div> => Hello World
112
+ * @param {string} str
113
+ * @returns {string}
114
+ */
115
+ export function removeHTML(str: string): string;
110
116
  /**
111
117
  * Unescape HTML characters like &lt, &gt, &amp and etc.
112
118
  * @param str
@@ -30,8 +30,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
30
30
  return (mod && mod.__esModule) ? mod : { "default": mod };
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.withSwitch = exports.firstNonNil = exports.unfold = exports.bootstrapVersion = exports.uniqueKey = exports.iterateKey = exports.delay = exports.fieldData = exports.getCurrencyAffixes = exports.getNumberDecimalLimit = exports.getNumberSeparators = exports.matchInputMask = exports.unmaskValue = exports.getInputMask = exports.convertFormatToMask = exports.convertFormatToMoment = exports.convertFormatToFlatpickr = exports.getLocaleDateFormatInfo = exports.formatOffset = exports.formatDate = exports.momentDate = exports.loadZones = exports.shouldLoadZones = exports.zonesLoaded = exports.offsetDate = exports.currentTimezone = exports.isValidDate = exports.getDateSetting = exports.guid = exports.uniqueName = exports.convertStringToHTMLElement = exports.unescapeHTML = exports.setActionProperty = exports.checkTrigger = exports.checkCondition = exports.checkJsonConditional = exports.checkCustomConditional = exports.getComponentActualValue = exports.checkSimpleConditional = exports.checkCalculated = exports.isMongoId = exports.boolValue = exports.getScriptPlugin = exports.getElementRect = exports.getPropertyValue = exports.getRandomComponentId = exports.evaluate = exports.moment = exports.ConditionOperators = exports.jsonLogic = void 0;
34
- exports.isSelectResourceWithObjectValue = exports.getItemTemplateKeys = exports.interpolateErrors = exports.getComponentSavedTypes = exports.componentValueTypes = exports._ = exports.getFocusableElements = exports.isInsideScopingComponent = exports.isPromise = exports.getDataParentComponent = exports.getComponentPath = exports.getComponentPathWithoutIndicies = exports.getBrowserInfo = exports.getIEBrowserVersion = exports.round = exports.getStringFromComponentPath = exports.isChildOf = exports.getArrayFromComponentPath = exports.isInputComponent = exports.interpolate = exports.Evaluator = exports.fastCloneDeep = exports.sanitize = exports.translateHTMLTemplate = exports.getContextButtons = exports.getContextComponents = exports.observeOverload = void 0;
33
+ exports.firstNonNil = exports.unfold = exports.bootstrapVersion = exports.uniqueKey = exports.iterateKey = exports.delay = exports.fieldData = exports.getCurrencyAffixes = exports.getNumberDecimalLimit = exports.getNumberSeparators = exports.matchInputMask = exports.unmaskValue = exports.getInputMask = exports.convertFormatToMask = exports.convertFormatToMoment = exports.convertFormatToFlatpickr = exports.getLocaleDateFormatInfo = exports.formatOffset = exports.formatDate = exports.momentDate = exports.loadZones = exports.shouldLoadZones = exports.zonesLoaded = exports.offsetDate = exports.currentTimezone = exports.isValidDate = exports.getDateSetting = exports.guid = exports.uniqueName = exports.convertStringToHTMLElement = exports.unescapeHTML = exports.removeHTML = exports.setActionProperty = exports.checkTrigger = exports.checkCondition = exports.checkJsonConditional = exports.checkCustomConditional = exports.getComponentActualValue = exports.checkSimpleConditional = exports.checkCalculated = exports.isMongoId = exports.boolValue = exports.getScriptPlugin = exports.getElementRect = exports.getPropertyValue = exports.getRandomComponentId = exports.evaluate = exports.moment = exports.ConditionOperators = exports.jsonLogic = void 0;
34
+ exports.isSelectResourceWithObjectValue = exports.getItemTemplateKeys = exports.interpolateErrors = exports.getComponentSavedTypes = exports.componentValueTypes = exports._ = exports.getFocusableElements = exports.isInsideScopingComponent = exports.isPromise = exports.getDataParentComponent = exports.getComponentPath = exports.getComponentPathWithoutIndicies = exports.getBrowserInfo = exports.getIEBrowserVersion = exports.round = exports.getStringFromComponentPath = exports.isChildOf = exports.getArrayFromComponentPath = exports.isInputComponent = exports.interpolate = exports.Evaluator = exports.fastCloneDeep = exports.sanitize = exports.translateHTMLTemplate = exports.getContextButtons = exports.getContextComponents = exports.observeOverload = exports.withSwitch = void 0;
35
35
  const lodash_1 = __importDefault(require("lodash"));
36
36
  exports._ = lodash_1.default;
37
37
  const fetch_ponyfill_1 = __importDefault(require("fetch-ponyfill"));
@@ -448,6 +448,16 @@ function setActionProperty(component, action, result, row, data, instance) {
448
448
  return component;
449
449
  }
450
450
  exports.setActionProperty = setActionProperty;
451
+ /**
452
+ * Removes HTML tags from string e.g. <div>Hello World</div> => Hello World
453
+ * @param {string} str
454
+ * @returns {string}
455
+ */
456
+ function removeHTML(str) {
457
+ const doc = new window.DOMParser().parseFromString(str, 'text/html');
458
+ return (doc.body.textContent || '').trim();
459
+ }
460
+ exports.removeHTML = removeHTML;
451
461
  /**
452
462
  * Unescape HTML characters like &lt, &gt, &amp and etc.
453
463
  * @param str
@@ -457,8 +467,9 @@ function unescapeHTML(str) {
457
467
  if (typeof window === 'undefined' || !('DOMParser' in window)) {
458
468
  return str;
459
469
  }
460
- const doc = new window.DOMParser().parseFromString(str, 'text/html');
461
- return doc.documentElement.textContent;
470
+ const elem = document.createElement('textarea');
471
+ elem.innerHTML = str;
472
+ return elem.value;
462
473
  }
463
474
  exports.unescapeHTML = unescapeHTML;
464
475
  /**
@@ -357,11 +357,12 @@ declare class Webform extends NestedDataComponent {
357
357
  */
358
358
  get submission(): Object;
359
359
  /**
360
- * @param submission
361
- * @param flags
362
- * @return {void}
363
- */
364
- onSetSubmission(submission: any, flags?: {}): void;
360
+ * Sets the submission value
361
+ * @param {object|null|undefined} submission - The submission to set.
362
+ * @param {object|null|undefined} flags - Any flags to apply when setting the submission.
363
+ * @return {void}
364
+ */
365
+ onSetSubmission(submission: object | null | undefined, flags?: object | null | undefined): void;
365
366
  /**
366
367
  * Sets a submission and returns the promise when it is ready.
367
368
  * @param submission
@@ -715,10 +715,11 @@ export default class Webform extends NestedDataComponent {
715
715
  this.setSubmission(submission);
716
716
  }
717
717
  /**
718
- * @param submission
719
- * @param flags
720
- * @return {void}
721
- */
718
+ * Sets the submission value
719
+ * @param {object|null|undefined} submission - The submission to set.
720
+ * @param {object|null|undefined} flags - Any flags to apply when setting the submission.
721
+ * @return {void}
722
+ */
722
723
  onSetSubmission(submission, flags = {}) {
723
724
  this.submissionSet = true;
724
725
  this.triggerChange(flags);
@@ -799,7 +800,8 @@ export default class Webform extends NestedDataComponent {
799
800
  formio.loadSubmissions({
800
801
  params: {
801
802
  state: 'draft',
802
- owner: userId
803
+ owner: userId,
804
+ sort: '-created'
803
805
  }
804
806
  }).then(submissions => {
805
807
  if (submissions.length > 0 && !this.options.skipDraftRestore) {
@@ -970,8 +970,14 @@ export default class WebformBuilder extends Component {
970
970
  else if (parent.formioComponent && parent.formioComponent.removeChildComponent) {
971
971
  parent.formioComponent.removeChildComponent(component);
972
972
  }
973
- if (component.input && componentInstance && componentInstance.parent) {
974
- _.unset(componentInstance._data, componentInstance.key);
973
+ if (component.input && componentInstance && parent.formioComponent) {
974
+ const parentDefaultValue = _.get(parent.formioComponent, 'component.defaultValue', null);
975
+ if (Array.isArray(parentDefaultValue)) {
976
+ parentDefaultValue.forEach(v => _.unset(v, componentInstance.key));
977
+ }
978
+ else if (typeof parentDefaultValue === 'object') {
979
+ _.unset(parentDefaultValue, componentInstance.key);
980
+ }
975
981
  }
976
982
  const rebuild = parent.formioComponent.rebuild() || Promise.resolve();
977
983
  rebuild.then(() => {
@@ -327,12 +327,23 @@ declare class Component extends Element {
327
327
  */
328
328
  loadRefs(element: HTMLElement, refs: object, referenceAttributeName?: string | undefined): void;
329
329
  setOpenModalElement(template: any): void;
330
- renderModalPreview(ctx: any): any;
331
- getModalPreviewTemplate(): any;
330
+ /**
331
+ * Renders a modal preview template and returns the markup as a string
332
+ * @param {object|null|undefined} ctx - The rendering context
333
+ * @return {string} - The modal preview markup
334
+ */
335
+ renderModalPreview(ctx: object | null | undefined): string;
336
+ getModalPreviewTemplate(): string;
332
337
  build(element: any): Promise<void>;
333
338
  get hasModalSaveButton(): boolean;
334
339
  render(children?: string, topLevel?: boolean): any;
335
- createTooltip(tooltipEl: any, settings?: {}): import("tippy.js").Instance<import("tippy.js").Props>[];
340
+ /**
341
+ * Creates the tooltip instance using tippy.js and returns it
342
+ * @param {HTMLElement} tooltipEl - HTML element to attach the tooltip
343
+ * @param {object|null|undefined} settings - tippy.js options
344
+ * @return {import('tippy.js').Tippy} - tippy.js instance
345
+ */
346
+ createTooltip(tooltipEl: HTMLElement, settings?: object | null | undefined): import('tippy.js').Tippy;
336
347
  attachTooltips(toolTipsRefs: any): void;
337
348
  createComponentModal(element: any, modalShouldBeOpened: any, currentValue: any): ComponentModal;
338
349
  attach(element: any): Promise<void>;
@@ -996,6 +996,11 @@ export default class Component extends Element {
996
996
  setOpenModalElement(template) {
997
997
  this.componentModal.setOpenModalElement(template || this.getModalPreviewTemplate());
998
998
  }
999
+ /**
1000
+ * Renders a modal preview template and returns the markup as a string
1001
+ * @param {object|null|undefined} ctx - The rendering context
1002
+ * @return {string} - The modal preview markup
1003
+ */
999
1004
  renderModalPreview(ctx) {
1000
1005
  return this.renderTemplate('modalPreview', ctx || {});
1001
1006
  }
@@ -1043,6 +1048,12 @@ export default class Component extends Element {
1043
1048
  }, topLevel);
1044
1049
  }
1045
1050
  }
1051
+ /**
1052
+ * Creates the tooltip instance using tippy.js and returns it
1053
+ * @param {HTMLElement} tooltipEl - HTML element to attach the tooltip
1054
+ * @param {object|null|undefined} settings - tippy.js options
1055
+ * @return {import('tippy.js').Tippy} - tippy.js instance
1056
+ */
1046
1057
  createTooltip(tooltipEl, settings = {}) {
1047
1058
  const tooltipAttribute = tooltipEl.getAttribute('data-tooltip');
1048
1059
  const tooltipDataTitle = tooltipEl.getAttribute('data-title');
@@ -1821,9 +1832,6 @@ export default class Component extends Element {
1821
1832
  messages = _.uniqBy(messages, message => message.message);
1822
1833
  if (this.refs.messageContainer) {
1823
1834
  this.setContent(this.refs.messageContainer, messages.map((message) => {
1824
- if (message.message && typeof message.message === 'string') {
1825
- message.message = message.message.replaceAll('<', '&lt;').replaceAll('>', '&gt;');
1826
- }
1827
1835
  return this.renderTemplate('message', { ...message });
1828
1836
  }).join(''));
1829
1837
  }
@@ -2537,7 +2545,7 @@ export default class Component extends Element {
2537
2545
  }
2538
2546
  this.calculatedValue = fastCloneDeep(calculatedValue);
2539
2547
  if (changed) {
2540
- if (!flags.noPristineChangeOnModified) {
2548
+ if (!flags.noPristineChangeOnModified && this.root.initialized) {
2541
2549
  this.pristine = false;
2542
2550
  }
2543
2551
  flags.triggeredComponentId = this.id;
@@ -79,7 +79,13 @@ export default class FormComponent extends Component {
79
79
  isHidden(): boolean;
80
80
  setValue(submission: any, flags?: {}): boolean;
81
81
  setSubFormValue(submission: any, flags: any): void;
82
- onSetSubFormValue(submission: any, flags: any): void;
82
+ /**
83
+ * Sets the subform value
84
+ * @param {object|null|undefined} submission - The submission to set.
85
+ * @param {object|null|undefined} flags - Any flags to apply when setting the submission.
86
+ * @return {void}
87
+ */
88
+ onSetSubFormValue(submission: object | null | undefined, flags: object | null | undefined): void;
83
89
  areAllComponentsEmpty(data: any): boolean;
84
90
  updateSubFormVisibility(): void;
85
91
  /**
@@ -440,7 +440,7 @@ export default class FormComponent extends Component {
440
440
  }
441
441
  else if (this.formSrc) {
442
442
  this.subFormLoading = true;
443
- const options = this.root.formio?.base && this.root.formio?.projectUrl
443
+ const options = this.root?.formio?.base && this.root?.formio?.projectUrl
444
444
  ? {
445
445
  base: this.root.formio.base,
446
446
  project: this.root.formio.projectUrl,
@@ -620,10 +620,11 @@ export default class FormComponent extends Component {
620
620
  && submission._id
621
621
  && this.subForm.formio
622
622
  && _.isEmpty(submission.data);
623
- if (shouldLoadSubmissionById) {
623
+ const shouldLoadDraftById = this.options.saveDraft && _.isEmpty(submission.data) && _.get(this.subForm, 'submission._id');
624
+ if (shouldLoadSubmissionById || shouldLoadDraftById) {
624
625
  const formId = submission.form || this.formObj.form || this.component.form;
625
- const submissionUrl = `${this.subForm.formio.formsUrl}/${formId}/submission/${submission._id}`;
626
- const options = this.root.formio?.base && this.root.formio?.projectUrl
626
+ const submissionUrl = `${this.subForm.formio.formsUrl}/${formId}/submission/${submission._id || this.subForm.submission._id}`;
627
+ const options = this.root?.formio?.base && this.root?.formio?.projectUrl
627
628
  ? {
628
629
  base: this.root.formio.base,
629
630
  project: this.root.formio.projectUrl,
@@ -638,6 +639,12 @@ export default class FormComponent extends Component {
638
639
  this.onSetSubFormValue(submission, flags);
639
640
  }
640
641
  }
642
+ /**
643
+ * Sets the subform value
644
+ * @param {object|null|undefined} submission - The submission to set.
645
+ * @param {object|null|undefined} flags - Any flags to apply when setting the submission.
646
+ * @return {void}
647
+ */
641
648
  onSetSubFormValue(submission, flags) {
642
649
  this.subForm.setValue(submission, flags);
643
650
  }
@@ -3,7 +3,7 @@ import { Formio } from '../../Formio';
3
3
  import ListComponent from '../_classes/list/ListComponent';
4
4
  import Input from '../_classes/input/Input';
5
5
  import Form from '../../Form';
6
- import { getRandomComponentId, boolValue, isPromise, componentValueTypes, getComponentSavedTypes, unescapeHTML, isSelectResourceWithObjectValue } from '../../utils/utils';
6
+ import { getRandomComponentId, boolValue, isPromise, componentValueTypes, getComponentSavedTypes, unescapeHTML, isSelectResourceWithObjectValue, removeHTML } from '../../utils/utils';
7
7
  import Choices from '../../utils/ChoicesWrapper';
8
8
  export default class SelectComponent extends ListComponent {
9
9
  static schema(...extend) {
@@ -1551,7 +1551,7 @@ export default class SelectComponent extends ListComponent {
1551
1551
  const getTemplateValue = (v) => {
1552
1552
  const itemTemplate = this.itemTemplate(v);
1553
1553
  return options.csv && itemTemplate
1554
- ? unescapeHTML(itemTemplate)
1554
+ ? removeHTML(itemTemplate)
1555
1555
  : itemTemplate;
1556
1556
  };
1557
1557
  if (Array.isArray(value)) {
@@ -107,6 +107,12 @@ export function checkCondition(component: any, row: any, data: any, form: any, i
107
107
  */
108
108
  export function checkTrigger(component: any, trigger: any, row: any, data: any, form: any, instance: any): mixed;
109
109
  export function setActionProperty(component: any, action: any, result: any, row: any, data: any, instance: any): any;
110
+ /**
111
+ * Removes HTML tags from string e.g. <div>Hello World</div> => Hello World
112
+ * @param {string} str
113
+ * @returns {string}
114
+ */
115
+ export function removeHTML(str: string): string;
110
116
  /**
111
117
  * Unescape HTML characters like &lt, &gt, &amp and etc.
112
118
  * @param str
@@ -395,6 +395,15 @@ export function setActionProperty(component, action, result, row, data, instance
395
395
  }
396
396
  return component;
397
397
  }
398
+ /**
399
+ * Removes HTML tags from string e.g. <div>Hello World</div> => Hello World
400
+ * @param {string} str
401
+ * @returns {string}
402
+ */
403
+ export function removeHTML(str) {
404
+ const doc = new window.DOMParser().parseFromString(str, 'text/html');
405
+ return (doc.body.textContent || '').trim();
406
+ }
398
407
  /**
399
408
  * Unescape HTML characters like &lt, &gt, &amp and etc.
400
409
  * @param str
@@ -404,8 +413,9 @@ export function unescapeHTML(str) {
404
413
  if (typeof window === 'undefined' || !('DOMParser' in window)) {
405
414
  return str;
406
415
  }
407
- const doc = new window.DOMParser().parseFromString(str, 'text/html');
408
- return doc.documentElement.textContent;
416
+ const elem = document.createElement('textarea');
417
+ elem.innerHTML = str;
418
+ return elem.value;
409
419
  }
410
420
  /**
411
421
  * Make HTML element from string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formio/js",
3
- "version": "5.0.0-dev.5633.3b83d8c",
3
+ "version": "5.0.0-dev.5633.3e0990b",
4
4
  "description": "JavaScript powered Forms with JSON Form Builder",
5
5
  "main": "lib/cjs/index.js",
6
6
  "exports": {