Skip to content

Commit

Permalink
Prevent rendering portals on elments that do not exist (#3587)
Browse files Browse the repository at this point in the history
* #3586 update form-builder so portals do not render on an empty div

* #3586 don notrun assign fields to conditonals if no conditionals

* Reassign process for conditional on if fieldID is defined

* Check by conditions array length

Co-authored-by: New0 <[email protected]>
  • Loading branch information
Shelob9 and New0 authored Jul 20, 2020
1 parent 9849137 commit 97a4b0e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
40 changes: 23 additions & 17 deletions clients/form-builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,36 @@ const HandleSave = ({ jQuery, formId }) => {
} else {
data_fields.config.processors = {};
}
//Clear all assignments of fields to conditionals
if (data_fields.config.hasOwnProperty("fields")) {
Object.keys(data_fields.config.fields).forEach((fieldId) => {
if (data_fields.config.fields.hasOwnProperty(fieldId)) {
data_fields.config.fields[fieldId].conditions = {
type: "",
};
}
});
}

//Reset assignments of fields to conditionals
conditionals.forEach((c) => {
const appliesTo = c.hasOwnProperty("config") ? c.config.appliesTo : [];
if (appliesTo) {
appliesTo.forEach((fieldId) => {

if( conditionals.length > 0 ){

//Clear all assignments of fields to conditionals
if (data_fields.config.hasOwnProperty("fields")) {
Object.keys(data_fields.config.fields).forEach((fieldId) => {
if (data_fields.config.fields.hasOwnProperty(fieldId)) {
data_fields.config.fields[fieldId].conditions = {
type: c.id,
type: "",
};
}
});
}
});

//Reset assignments of fields to conditionals
conditionals.forEach((c) => {
const appliesTo = c.hasOwnProperty("config") ? c.config.appliesTo : [];
if (appliesTo) {
appliesTo.forEach((fieldId) => {
if (data_fields.config.fields.hasOwnProperty(fieldId)) {
data_fields.config.fields[fieldId].conditions = {
type: c.id,
};
}
});
}
});
}


apiFetch({
path: `/cf-api/v2/forms/${formId}`,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"ie > 8"
],
"dependencies": {
"@calderajs/form-builder": "1.2.4",
"@calderajs/form-builder": "^1.2.5",
"@cypress/webpack-preprocessor": "^4.1.1",
"@wordpress/api-fetch": "latest",
"@wordpress/keycodes": "^2.3.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1091,10 +1091,10 @@
"@babel/preset-env" "^7.3.1"
"@babel/preset-react" "^7.0.0"

"@calderajs/[email protected].4":
version "1.2.4"
resolved "https://registry.yarnpkg.com/@calderajs/form-builder/-/form-builder-1.2.4.tgz#37bb4caa46f2bc8e45bdf3257c45d0db89344ece"
integrity sha512-K1fQsbx6n0pCOPBGhSLDaJ2CmftR5tCA2y14KvN67MZn0i8fzaMb3iURewOeDUqp94cXRnk+Y7BDjJsPnTtR9w==
"@calderajs/form-builder@^1.2.5":
version "1.2.5"
resolved "https://registry.yarnpkg.com/@calderajs/form-builder/-/form-builder-1.2.5.tgz#9c7e33c925fe4694f1069e9bb4db702152b7ffde"
integrity sha512-2g5S92+S4k0j5Dzpwohm/CYRtgbm5F3RWfxD1JXsqA89IGgCuk8T2FL5IAUFbKPGdXSj0QrX4AHlguBBQnPomg==
dependencies:
"@types/dot-object" "^1.7.0"
deep-clone "^3.0.3"
Expand Down

0 comments on commit 97a4b0e

Please sign in to comment.