Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.x - FIO-8426: changes required for eSignature #5633

Merged
merged 5 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/Webform.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';
import moment from 'moment';
import { compareVersions } from 'compare-versions';
import { Component } from '@formio/core';

Check warning on line 4 in src/Webform.js

View workflow job for this annotation

GitHub Actions / setup

'Component' is defined but never used
import EventEmitter from './EventEmitter';
import i18nDefaults from './i18n';
import { Formio } from './Formio';
Expand Down Expand Up @@ -811,6 +811,19 @@
this.setSubmission(submission);
}

/**
* Sets the submission value
* @param {object|null|undefined} submission - The submission to set.
* @param {object|null|undefined} flags - Any flags to apply when setting the submission.
* @return {void}
Copy link
Contributor

@brendanbond brendanbond Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a HUGE nit, but the incoming PR from Travis will cause the linter to complain about this - can we get into the habit of adding descriptions and types for each (even any will do, although I have a JSON type in Form.js)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

*/
onSetSubmission(submission, flags = {}) {
this.submissionSet = true;
this.triggerChange(flags);
this.emit('beforeSetSubmission', submission);
this.setValue(submission, flags);
}

/**
* Sets a submission and returns the promise when it is ready.
* @param submission
Expand All @@ -830,10 +843,7 @@
...resolveFlags
};
}
this.submissionSet = true;
this.triggerChange(flags);
this.emit('beforeSetSubmission', submission);
this.setValue(submission, flags);
this.onSetSubmission(submission, flags);
return this.submissionReadyResolve(submission);
},
(err) => this.submissionReadyReject(err)
Expand Down
48 changes: 34 additions & 14 deletions src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,15 @@ export default class Component extends Element {
this.componentModal.setOpenModalElement(template || this.getModalPreviewTemplate());
}

/**
* Renders a modal preview template and returns the markup as a string
* @param {object|null|undefined} ctx - The rendering context
* @return {string} - The modal preview markup
*/
renderModalPreview(ctx) {
return this.renderTemplate('modalPreview', ctx || {});
}

getModalPreviewTemplate() {
const dataValue = this.component.type === 'password' ? this.dataValue.replace(/./g, '•') : this.dataValue;
let modalLabel;
Expand All @@ -1184,7 +1193,7 @@ export default class Component extends Element {
modalLabel = { className: 'field-required' };
}

return this.renderTemplate('modalPreview', {
return this.renderModalPreview({
previewText: this.getValueAsString(dataValue, { modalPreview: true }) || this.t('Click to set value'),
messages: '',
labelInfo: modalLabel,
Expand Down Expand Up @@ -1227,22 +1236,33 @@ export default class Component extends Element {
}
}

/**
* Creates the tooltip instance using tippy.js and returns it
* @param {HTMLElement} tooltipEl - HTML element to attach the tooltip
* @param {object|null|undefined} settings - tippy.js options
* @return {import('tippy.js').Tippy} - tippy.js instance
*/
createTooltip(tooltipEl, settings = {}) {
const tooltipAttribute = tooltipEl.getAttribute('data-tooltip');
const tooltipDataTitle = tooltipEl.getAttribute('data-title');
const tooltipText = this.interpolate(tooltipDataTitle || tooltipAttribute)
.replace(/(?:\r\n|\r|\n)/g, '<br />');

return tippy(tooltipEl, {
allowHTML: true,
trigger: 'mouseenter click focus',
placement: 'right',
zIndex: 10000,
interactive: true,
...settings,
content: this.t(this.sanitize(tooltipText), { _userInput: true }),
});
}

attachTooltips(toolTipsRefs) {
toolTipsRefs?.forEach((tooltip, index) => {
if (tooltip) {
const tooltipAttribute = tooltip.getAttribute('data-tooltip');
const tooltipDataTitle = tooltip.getAttribute('data-title');
const tooltipText = this.interpolate(tooltipDataTitle || tooltipAttribute)
.replace(/(?:\r\n|\r|\n)/g, '<br />');

this.tooltips[index] = tippy(tooltip, {
allowHTML: true,
trigger: 'mouseenter click focus',
placement: 'right',
zIndex: 10000,
interactive: true,
content: this.t(this.sanitize(tooltipText), { _userInput: true }),
});
this.tooltips[index] = this.createTooltip(tooltip);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice

}
});
}
Expand Down
11 changes: 10 additions & 1 deletion src/components/form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,18 @@ export default class FormComponent extends Component {
});
}
else {
this.subForm.setValue(submission, flags);
this.onSetSubFormValue(submission, flags);
}
}
/**
* Sets the subform value
* @param {object|null|undefined} submission - The submission to set.
* @param {object|null|undefined} flags - Any flags to apply when setting the submission.
* @return {void}
*/
onSetSubFormValue(submission, flags) {
this.subForm.setValue(submission, flags);
}

isEmpty(value = this.dataValue) {
return value === null || _.isEqual(value, this.emptyValue) || (this.areAllComponentsEmpty(value?.data) && !value?._id);
Expand Down
2 changes: 1 addition & 1 deletion src/components/signature/Signature.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default class SignatureComponent extends Input {
}

getModalPreviewTemplate() {
return this.renderTemplate('modalPreview', {
return this.renderModalPreview({
previewText: this.dataValue ?
`<img src=${this.dataValue} ${this._referenceAttributeName}='openModal' style="width: 100%;height: 100%;" />` :
this.t('Click to Sign')
Expand Down
Loading