Skip to content

Commit

Permalink
FIO-9173: Merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinanciani committed Dec 17, 2024
2 parents 49919b4 + 7d4e90c commit 45b9e00
Show file tree
Hide file tree
Showing 72 changed files with 4,058 additions and 2,139 deletions.
315 changes: 305 additions & 10 deletions Changelog.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@
},
"homepage": "https://github.com/formio/formio.js#readme",
"dependencies": {
"@formio/bootstrap": "3.0.0-dev.98.17ba6ea",
"@formio/bootstrap": "3.0.0-dev.111.ae7f187",
"@formio/choices.js": "^10.2.1",
"@formio/core": "2.1.0-dev.191.8c609ab",
"@formio/text-mask-addons": "^3.8.0-formio.4",
"@formio/core": "2.1.0-dev.193.68cf8c3",
"@formio/text-mask-addons": "3.8.0-formio.4",
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
"abortcontroller-polyfill": "^1.7.5",
"autocompleter": "^8.0.4",
Expand Down
70 changes: 35 additions & 35 deletions resources/latest.json

Large diffs are not rendered by default.

54 changes: 24 additions & 30 deletions src/Webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@ export default class Webform extends NestedDataComponent {
try {
// Do not set the form again if it has been already set
if (isFormAlreadySet && JSON.stringify(this._form) === JSON.stringify(form)) {
this.formReadyResolve();
return Promise.resolve();
}

Expand All @@ -669,13 +670,10 @@ export default class Webform extends NestedDataComponent {
if (this.onSetForm) {
this.onSetForm(_.cloneDeep(this._form), form);
}

if (this.parent?.component?.modalEdit) {
return Promise.resolve();
}
} catch (err) {
console.warn(err);
// If provided form is not a valid JSON object, do not set it too
this.formReadyReject(err);
return Promise.resolve();
}

Expand Down Expand Up @@ -959,6 +957,9 @@ export default class Webform extends NestedDataComponent {
}

getValue() {
if (!this._submission) {
this._submission = {};
}
if (!this._submission.data) {
this._submission.data = {};
}
Expand Down Expand Up @@ -1271,32 +1272,24 @@ export default class Webform extends NestedDataComponent {
}

// Mark any components as invalid if in a custom message.
const componentErrors = {};
errors.forEach((err) => {
const { components = [] } = err;
if (err.component) {
components.push(err.component);
const path = err.path || err.context?.path || err.component?.key;
if (!componentErrors[path]) {
componentErrors[path] = [];
}
componentErrors[path].push(err);
});

if (err.path) {
components.push(err.path);
// Iterate through all of our component errors and apply them to the components.
for (let path in componentErrors) {
const component = this.getComponent(path);
const errors = componentErrors[path];
if (component) {
component.serverErrors = errors.filter((err) => err.fromServer);
component.setCustomValidity(errors, true)
}

components.forEach((path) => {
const originalPath = getStringFromComponentPath(path);
const component = this.getComponent(path, _.identity, originalPath);

if (err.fromServer) {
if (component.serverErrors) {
component.serverErrors.push(err);
} else {
component.serverErrors = [err];
}
}
const components = _.compact(Array.isArray(component) ? component : [component]);

components.forEach((component) => component.setCustomValidity(err.message, true));
});
});
}

const displayedErrors = [];
if (errors.length) {
Expand Down Expand Up @@ -1521,7 +1514,7 @@ export default class Webform extends NestedDataComponent {
});
}

submitForm(options = {}) {
submitForm(options = {}, local = false) {
this.clearServerErrors();

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -1556,6 +1549,7 @@ export default class Webform extends NestedDataComponent {
return reject("Invalid Submission");
}
const errors = this.validate(submission.data, {
local,
dirty: true,
silentCheck: false,
process: "submit",
Expand All @@ -1575,11 +1569,11 @@ export default class Webform extends NestedDataComponent {

this.everyComponent((comp) => {
if (submission._vnote && comp.type === "form" && comp.component.reference) {
_.get(submission.data, comp.path, {})._vnote = submission._vnote;
_.get(submission.data, local ? comp.paths?.localDataPath : comp.path, {})._vnote = submission._vnote;
}
const { persistent } = comp.component;
if (persistent === "client-only") {
_.unset(submission.data, comp.path);
_.unset(submission.data, local ? comp.paths?.localDataPath : comp.path);
}
});

Expand Down Expand Up @@ -1777,7 +1771,7 @@ export default class Webform extends NestedDataComponent {
return;
}
const captchaComponent = [];
eachComponent(this.components, (component) => {
this.eachComponent((component) => {
if (/^(re)?captcha$/.test(component.type) && component.component.eventType === 'formLoad') {
captchaComponent.push(component);
}
Expand Down
73 changes: 32 additions & 41 deletions src/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -933,32 +933,20 @@ export default class WebformBuilder extends Component {
const compKey = (group === 'resource') ? `component-${key}` : key;
const draggableComponent = this.groups[group]?.components[compKey] || {};

if (draggableComponent.disableSiblings) {
if (draggableComponent.disableSiblings || draggableComponent.uniqueComponent) {
let isCompAlreadyExists = false;
eachComponent(this.webform.components, (component) => {
if (component.type === draggableComponent.schema.type) {
isCompAlreadyExists = true;
return;
}
}, true);
if (isCompAlreadyExists) {
this.webform.redraw();
this.webform.setAlert('danger', `You cannot add more than one ${draggableComponent.key} component to one page.`);
return;
}
}

if (draggableComponent.uniqueComponent) {
let isCompAlreadyExists = false;
eachComponent(this.webform.components, (component) => {
if (component.key === draggableComponent.schema.key) {
if (
(draggableComponent.disableSiblings && component.type === draggableComponent.schema.type) ||
(draggableComponent.uniqueComponent && component.component.key === draggableComponent.schema.key)
) {
isCompAlreadyExists = true;
return;
}
}, true);
if (isCompAlreadyExists) {
this.webform.redraw();
this.webform.setAlert('danger', `You cannot add more than one ${draggableComponent.title} component to one page.`);
this.webform.setAlert('danger', `You cannot add more than one ${_.get(draggableComponent, draggableComponent.uniqueComponent ? 'title' : 'key')} component to one page.`);
return;
}
}
Expand Down Expand Up @@ -1052,15 +1040,19 @@ export default class WebformBuilder extends Component {
}
this.keyboardActionsEnabled = keyboardActionsEnabled;

const isSubmitButton = (comp) => {
return (comp.type === 'button') && ((comp.action === 'submit') || !comp.action);
}
const { display, noAddSubmitButton, noDefaultSubmitButton } = this.options;
const { _id, components } = form;

const isShowSubmitButton = !this.options.noDefaultSubmitButton
&& (!form.components.length || !form.components.find(comp => isSubmitButton(comp)));
const isSubmitButton = ({ type, action }) => type === 'button' && (action === 'submit' || !action);
const hasSubmitButton = components.some(isSubmitButton);
// Add submit button if form display was switched from wizard
// Don't add if there is noAddSubmitButton flag passed, or the form has id, or the form has a submit button already
const shouldAddSubmitButton =
(display === 'wizard' && !hasSubmitButton) ||
(!noAddSubmitButton && !_id && !hasSubmitButton);

// Ensure there is at least a submit button.
if (isShowSubmitButton) {
// Ensure there is at least a submit button.
if (!noDefaultSubmitButton && shouldAddSubmitButton) {
form.components.push({
type: 'button',
label: 'Submit',
Expand Down Expand Up @@ -1224,6 +1216,7 @@ export default class WebformBuilder extends Component {
'conditional',
'customConditional',
'id',
'logic',
'fields.day.required',
'fields.month.required',
'fields.year.required',
Expand All @@ -1250,6 +1243,12 @@ export default class WebformBuilder extends Component {
parentComponent.tabs[tabIndex].splice(index, 1, newComp);
newComp.checkValidity = () => true;
newComp.build(defaultValueComponent.element);
if (this.preview && !this.preview.defaultChanged) {
const defaultValue = _.get(this.preview._data, this.editForm._data.key);
if (_.isObject(defaultValue) && !_.isArray(defaultValue)) {
this.editForm._data.defaultValue = defaultValue;
}
}
}
}
else {
Expand All @@ -1263,6 +1262,7 @@ export default class WebformBuilder extends Component {
dataPath = getStringFromComponentPath(path);
}

this.preview.defaultChanged = true;
_.set(this.preview._data, dataPath, changed.value);
_.set(this.webform._data, dataPath, changed.value);
}
Expand All @@ -1275,25 +1275,14 @@ export default class WebformBuilder extends Component {
findRepeatablePaths() {
const repeatablePaths = [];
const keys = new Map();

eachComponent(this.form.components, (comp, path) => {
if (!comp.key) {
return;
}

if (keys.has(comp.key)) {
if (keys.get(comp.key).includes(path)) {
repeatablePaths.push(path);
}
else {
keys.set(comp.key, [...keys.get(comp.key), path]);
}
eachComponent(this.form.components, (comp, path, components, parent, paths) => {
if (keys.has(paths.dataPath)) {
repeatablePaths.push(paths.dataPath);
}
else {
keys.set(comp.key, [path]);
keys.set(paths.dataPath, true);
}
}, true);

return repeatablePaths;
}

Expand Down Expand Up @@ -1361,6 +1350,7 @@ export default class WebformBuilder extends Component {

const rebuild = parentComponent.rebuild() || Promise.resolve();
return rebuild.then(() => {
parentComponent.resetValue();
const schema = parentContainer ? parentContainer[index] : (comp ? comp.schema : []);
this.emitSaveComponentEvent(
schema,
Expand Down Expand Up @@ -1454,7 +1444,8 @@ export default class WebformBuilder extends Component {
helplinks: this.helplinks,
}));
this.editForm.attach(this.componentEdit.querySelector(`[${this._referenceAttributeName}="editForm"]`));
this.updateComponent(this.editForm.submission.data ?? component);
const editFormData = this.editForm.submission?.data;
this.updateComponent(editFormData?.componentJson || editFormData || component);
this.attachEditComponentControls(component, parent, isNew, original, ComponentClass);
});
});
Expand Down
49 changes: 17 additions & 32 deletions src/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export default class Wizard extends Webform {

attachHeader() {
const isAllowPrevious = this.isAllowPrevious();
this.attachTooltips(this.refs[`${this.wizardKey}-tooltip`], this.currentPanel.tooltip);
this.attachTooltips(this.refs[`${this.wizardKey}-tooltip`], this.currentPanel?.tooltip);

if (this.isBreadcrumbClickable() || isAllowPrevious) {
this.refs[`${this.wizardKey}-link`]?.forEach((link, index) => {
Expand Down Expand Up @@ -690,7 +690,10 @@ export default class Wizard extends Webform {
}
this.redraw().then(() => {
this.checkData(this.submission.data);
this.validateCurrentPage();
const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
if (this.alert) {
this.showErrors(errors, true, true);
}
});
return Promise.resolve();
}
Expand Down Expand Up @@ -801,9 +804,11 @@ export default class Wizard extends Webform {
});
}

// Validate the form, before go to the next page
const errors = this.validateCurrentPage({ dirty: true });
if (errors.length === 0) {
// Validate the form before going to the next page
const currentPageErrors = this.validateCurrentPage({ dirty: true });
const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : currentPageErrors;
// allow going to the next page if the current page is valid, even if there are form level errors
if (currentPageErrors.length === 0) {
this.checkData(this.submission.data);
return this.beforePage(true).then(() => {
return this.setPage(this.getNextPage()).then(() => {
Expand All @@ -819,13 +824,14 @@ export default class Wizard extends Webform {
else {
this.currentPage.components.forEach((comp) => comp.setPristine(false));
this.scrollIntoView(this.element, true);
return Promise.reject(super.showErrors(errors, true));
return Promise.reject(this.showErrors(errors, true));
}
}

validateCurrentPage(flags = {}) {
const components = this.currentPage?.components.map((component) => component.component);
// Accessing the parent ensures the right instance (whether it's the parent Wizard or a nested Wizard) performs its validation
return this.currentPage?.parent.validateComponents(this.currentPage.component.components, this.currentPage.parent.data, flags);
return this.currentPage?.parent.validateComponents(components, this.root.data, flags);
}

emitPrevPage() {
Expand Down Expand Up @@ -1000,7 +1006,8 @@ export default class Wizard extends Webform {

onChange(flags, changed, modified, changes) {
super.onChange(flags, changed, modified, changes);
const errors = this.validate(this.localData, { dirty: false });
// The onChange loop doesn't need all components for wizards
const errors = this.submitted ? this.validate(this.localData, { dirty: true }) : this.validateCurrentPage();
if (this.alert) {
this.showErrors(errors, true, true);
}
Expand Down Expand Up @@ -1036,13 +1043,6 @@ export default class Wizard extends Webform {
}
}

redraw() {
if (this.parent?.component?.modalEdit) {
return this.parent.redraw();
}
return super.redraw();
}

rebuild() {
const currentPage = this.page;
const setCurrentPage = () => this.setPage(currentPage);
Expand All @@ -1065,23 +1065,8 @@ export default class Wizard extends Webform {
);
}

get errors() {
if (!this.isLastPage()) {
return this.currentPage.errors;
}

return super.errors;
}

showErrors(errors, triggerEvent) {
if (this.hasExtraPages) {
this.subWizards.forEach((subWizard) => {
if(Array.isArray(subWizard.errors)) {
errors = [...errors, ...subWizard.errors]
}
})
};
return super.showErrors(errors, triggerEvent)
get errors() {
return !this.isLastPage() && !this.submitted ? this.currentPage.errors : super.errors;
}

focusOnComponent(key) {
Expand Down
Loading

0 comments on commit 45b9e00

Please sign in to comment.