Skip to content

Commit

Permalink
Fixing the conditions to use the correct path.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Nov 19, 2024
1 parent 305d7f0 commit 259ad94
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"dependencies": {
"@formio/bootstrap": "3.0.0-dev.98.17ba6ea",
"@formio/choices.js": "^10.2.1",
"@formio/core": "v2.1.0-dev.174.9a3c6ec",
"@formio/core": "2.1.0-dev.189.e38e07a",
"@formio/text-mask-addons": "^3.8.0-formio.3",
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
"abortcontroller-polyfill": "^1.7.5",
Expand Down
7 changes: 4 additions & 3 deletions src/Webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ export default class Webform extends NestedDataComponent {
});
}

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

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -1554,6 +1554,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 @@ -1573,11 +1574,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
1 change: 1 addition & 0 deletions src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3450,6 +3450,7 @@ export default class Component extends Element {
component: this.component,
data,
row,
local: !!flags.local,
value: this.validationValue,
parent: this.parent?.component,
paths: this.paths,
Expand Down
1 change: 1 addition & 0 deletions src/components/_classes/nested/NestedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ export default class NestedComponent extends Field {
components,
instances: this.componentsMap,
data: data,
local: !!flags.local,
scope: { errors: [] },
parent: this.component,
parentPaths: this.paths,
Expand Down
2 changes: 1 addition & 1 deletion src/components/form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ export default class FormComponent extends Component {
}
this.subForm.nosubmit = false;
this.subForm.submitted = true;
return this.subForm.submitForm().then(result => {
return this.subForm.submitForm({}, true).then(result => {
this.subForm.loading = false;
this.subForm.showAllErrors = false;
this.dataValue = result.submission;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/conditionOperators/DateGreaterThan.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class DateGeaterThan extends ConditionOperator {
}

execute(options, functionName = 'isAfter') {
const { value, instance, conditionComponentPath } = options;
const { value, instance, path } = options;

if (!value) {
return false;
Expand All @@ -27,7 +27,7 @@ export default class DateGeaterThan extends ConditionOperator {
let conditionTriggerComponent = null;

if (instance?.root?.getComponent) {
conditionTriggerComponent = instance.root.getComponent(conditionComponentPath);
conditionTriggerComponent = instance.root.getComponent(path);
}

if ( conditionTriggerComponent && conditionTriggerComponent.isPartialDay && conditionTriggerComponent.isPartialDay(value)) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/conditionOperators/IsEmptyValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export default class IsEmptyValue extends ConditionOperator {
return false;
}

execute({ value, instance, conditionComponentPath }) {
execute({ value, instance, path }) {
const isEmptyValue = _.isEmpty(_.isNumber(value)? String(value): value);

if (instance?.root?.getComponent) {
const conditionTriggerComponent = instance.root.getComponent(conditionComponentPath);
const conditionTriggerComponent = instance.root.getComponent(path);
return conditionTriggerComponent?.isEmpty ? conditionTriggerComponent.isEmpty() : isEmptyValue;
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/conditionOperators/IsEqualTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class IsEqualTo extends ConditionOperator {
return 'Is Equal To';
}

execute({ value, comparedValue, instance, conditionComponentPath }) {
execute({ value, comparedValue, instance, path }) {
if ((value || value === false) && comparedValue && typeof value !== typeof comparedValue && _.isString(comparedValue)) {
try {
comparedValue = JSON.parse(comparedValue);
Expand All @@ -21,7 +21,7 @@ export default class IsEqualTo extends ConditionOperator {
}

if (instance?.root?.getComponent) {
const conditionTriggerComponent = instance.root.getComponent(conditionComponentPath);
const conditionTriggerComponent = instance.root.getComponent(path);

if (
conditionTriggerComponent
Expand Down
7 changes: 3 additions & 4 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,21 +245,20 @@ function getConditionalPathsRecursive(conditionPaths, data) {

const conditionalPaths = instance?.parent?.type === 'datagrid' || instance?.parent?.type === 'editgrid' ? [] : getConditionalPathsRecursive(splittedConditionPath, data);

if (conditionalPaths.length>0) {
if (conditionalPaths.length > 0) {
return conditionalPaths.map((path) => {
const value = getComponentActualValue(path, data, row);

const ConditionOperator = ConditionOperators[operator];
return ConditionOperator
? new ConditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath })
? new ConditionOperator().getResult({ value, comparedValue, instance, component, path })
: true;
});
}
else {
const value = getComponentActualValue(conditionComponentPath, data, row);
const СonditionOperator = ConditionOperators[operator];
return СonditionOperator
? new СonditionOperator().getResult({ value, comparedValue, instance, component, conditionComponentPath })
? new СonditionOperator().getResult({ value, comparedValue, instance, component, path: conditionComponentPath })
: true;
}
});
Expand Down
26 changes: 14 additions & 12 deletions test/unit/Tags.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,22 @@ describe('Tags Component', function() {
const element = document.createElement('div');

Formio.createForm(element, comp6).then(form => {
const tags = form.getComponent('tags');
// tags.setValue(['1', '2', '3']);
Harness.setTagsValue(['test', 'test1', 'test2'], tags);
tags.choices.input.element.focus();

setTimeout(() => {
assert.equal(tags.errors.length, 0, 'Tags should be valid while changing');
tags.choices.input.element.dispatchEvent(new Event('blur'));

const tags = form.getComponent('tags');
// tags.setValue(['1', '2', '3']);
Harness.setTagsValue(['test', 'test1', 'test2'], tags);
tags.choices.input.element.focus();

setTimeout(() => {
assert.equal(tags.errors.length, 1, 'Should set error after Tags component was blurred');
done();
}, 500);
}, 350);
assert.equal(tags.errors.length, 0, 'Tags should be valid while changing');
tags.choices.input.element.dispatchEvent(new Event('blur'));

setTimeout(() => {
assert.equal(tags.errors.length, 1, 'Should set error after Tags component was blurred');
done();
}, 500);
}, 350);
}, 10);
}).catch(done);
});
});
15 changes: 10 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,15 @@
fuse.js "^6.6.2"
redux "^4.2.0"

"@formio/core@v2.1.0-dev.174.9a3c6ec":
version "2.1.0-dev.174.9a3c6ec"
resolved "https://registry.yarnpkg.com/@formio/core/-/core-2.1.0-dev.174.9a3c6ec.tgz#f223b5ce4f374a9f4e922dada0af7c029320e035"
integrity sha512-QQK04dP0xBFa3vuhiOi+TUP8Zwqlg38qxzHgDmBwSlRO5XqQIObPJpSSnv2VA8H7fBWWiV2g7AErHBxugJW7Rw==
"@formio/core@2.1.0-dev.189.e38e07a":
version "2.1.0-dev.189.e38e07a"
resolved "https://registry.npmjs.org/@formio/core/-/core-2.1.0-dev.189.e38e07a.tgz#6206322a8a644704651eaa03732f3b93aa2139ac"
integrity sha512-TXa3xTYdaYKWNvc1WzummmNqekFrGhiJmXFecJAqQhmT1SG0dgELE2lH99jHN6AAj5+8VL0TKFKYtqgUy48kHQ==
dependencies:
browser-cookies "^1.2.0"
core-js "^3.38.0"
dayjs "^1.11.12"
dompurify "^3.1.6"
dompurify "^3.1.7"
eventemitter3 "^5.0.0"
fast-json-patch "^3.1.1"
fetch-ponyfill "^7.1.0"
Expand Down Expand Up @@ -2498,6 +2498,11 @@ dompurify@^3.1.6:
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-3.1.6.tgz#43c714a94c6a7b8801850f82e756685300a027e2"
integrity sha512-cTOAhc36AalkjtBpfG6O8JimdTMWNXjiePT2xQH/ppBGi/4uIpmj8eKyIkMJErXWARyINV/sB38yf8JCLF5pbQ==

dompurify@^3.1.7:
version "3.2.0"
resolved "https://registry.npmjs.org/dompurify/-/dompurify-3.2.0.tgz#53c414317c51503183696fcdef6dd3f916c607ed"
integrity sha512-AMdOzK44oFWqHEi0wpOqix/fUNY707OmoeFDnbi3Q5I8uOpy21ufUA5cDJPr0bosxrflOVD/H2DMSvuGKJGfmQ==

downloadjs@^1.4.7:
version "1.4.7"
resolved "https://registry.npmjs.org/downloadjs/-/downloadjs-1.4.7.tgz#f69f96f940e0d0553dac291139865a3cd0101e3c"
Expand Down

0 comments on commit 259ad94

Please sign in to comment.