Skip to content

Commit

Permalink
Merge branch 'master' of github.com:formio/core into adding-component…
Browse files Browse the repository at this point in the history
…-paths
  • Loading branch information
travist committed Nov 18, 2024
2 parents 5eb04f8 + 555beb3 commit 36f3a6f
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 1 deletion.
129 changes: 129 additions & 0 deletions src/process/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4549,6 +4549,135 @@ describe('Process Tests', function () {
});
});

it("Should validate Nested Form's components if it should not be cleared and no data provided", async function () {
const nestedForm = {
key: 'form',
type: 'form',
display: 'form',
input: true,
components: [
{
key: 'textField',
type: 'textfield',
validate: {
required: true,
},
input: true,
},
],
};
const submission = {
data: {
submit: true,
},
state: 'submitted',
};
const form = {
title: 'Parent Form',
name: 'parentForm',
path: 'parentform',
type: 'form',
display: 'form',
components: [
nestedForm,
{
...nestedForm,
key: 'form1',
},
{
type: 'button',
label: 'Submit',
key: 'submit',
input: true,
tableView: false,
},
],
};
const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true,
},
};
processSync(context);
context.processors = ProcessTargets.evaluator;
const scope = processSync(context);
expect((scope as ValidationScope).errors).to.have.length(2);
});

it("Should validate Nested Form's components if it should not be cleared and no data provided and the parent form has errors itself", async function () {
const nestedForm = {
key: 'form',
type: 'form',
input: true,
components: [
{
key: 'textField',
type: 'textfield',
validate: {
required: true,
},
input: true,
},
],
};
const submission = {
data: {
submit: true,
},
state: 'submitted',
};
const form = {
title: 'Parent Form',
name: 'parentForm',
path: 'parentform',
type: 'form',
display: 'form',
components: [
{
key: 'textField',
type: 'textfield',
validate: {
required: true,
},
input: true,
},
nestedForm,
{
...nestedForm,
key: 'form1',
},
{
type: 'button',
label: 'Submit',
key: 'submit',
input: true,
tableView: false,
},
],
};
const context = {
form,
submission,
data: submission.data,
components: form.components,
processors: ProcessTargets.submission,
scope: {},
config: {
server: true,
},
};
processSync(context);
context.processors = ProcessTargets.evaluator;
const scope = processSync(context);
expect((scope as ValidationScope).errors).to.have.length(3);
});

it('Should not return errors for empty multiple values for url and dateTime', function () {
const form = {
_id: '671f7fbeaf87b0e2a26e4212',
Expand Down
2 changes: 1 addition & 1 deletion src/utils/formUtil/eachComponentDataAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const eachComponentDataAsync = async (
parent?: Component,
parentPaths?: ComponentPaths,
) => {
if (!components || !data) {
if (!components) {
return;
}
return await eachComponentAsync(
Expand Down

0 comments on commit 36f3a6f

Please sign in to comment.