Skip to content

Commit 21a2c93

Browse files
authored
Merge pull request #1828 from ProcessMaker/bugfix/FOUR-24596-A
FOUR-24596 It is not possible delete page in screen form even when it has no relation to any page
2 parents 2dae12d + ec5b3c4 commit 21a2c93

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

src/components/vue-form-builder.vue

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,14 +1382,7 @@ export default {
13821382
return index > this.pageDelete ? index - 1 : index;
13831383
},
13841384
// This function is used to calculate the new index of the references FormRecordList
1385-
calcNewIndexForFormRecordList(index, referencedBy, config) {
1386-
if (config[this.pageDelete].items.length > 0) {
1387-
throw new Error(
1388-
`${this.$t(
1389-
"Can not delete this page, it is referenced by"
1390-
)}: ${referencedBy}`
1391-
);
1392-
}
1385+
calcNewIndexForFormRecordList(index, referencedBy) {
13931386
return index > this.pageDelete ? index - 1 : index;
13941387
},
13951388
// Update Record list references
@@ -1398,11 +1391,12 @@ export default {
13981391
page.items.forEach((item) => {
13991392
if (item.component === "FormRecordList") {
14001393
// eslint-disable-next-line no-param-reassign
1401-
item.config.form = this.calcNewIndexForFormRecordList(
1402-
item.config.form * 1,
1403-
item.config.label,
1404-
this.config,
1405-
);
1394+
if (this.isValidInteger(item.config.form)) {
1395+
item.config.form = this.calcNewIndexForFormRecordList(
1396+
item.config.form * 1,
1397+
item.config.label,
1398+
);
1399+
}
14061400
}
14071401
});
14081402
});
@@ -1426,6 +1420,9 @@ export default {
14261420
},
14271421
async deletePage() {
14281422
const back = _.cloneDeep(this.config);
1423+
if(!this.isNotReferenceToRecordForm()) {
1424+
return;
1425+
}
14291426
try {
14301427
this.updateRecordListReferences();
14311428
this.updateNavigationButtonsReferences();
@@ -1446,6 +1443,32 @@ export default {
14461443
});
14471444
this.$store.dispatch("clipboardModule/pushState", this.clipboardPage.items);
14481445
},
1446+
isNotReferenceToRecordForm() {
1447+
for (let page of this.config) {
1448+
for (let item of page.items) {
1449+
if (item.component === "FormRecordList") {
1450+
if (this.isValidInteger(item.config.form) && Number(item.config.form) === this.pageDelete) {
1451+
const referencedBy = item.config.label;
1452+
const message = `${this.$t("Can not delete this page, it is referenced by")}: ${referencedBy}`;
1453+
globalObject.ProcessMaker.alert(message, "danger");
1454+
return false;
1455+
}
1456+
}
1457+
}
1458+
}
1459+
return true;
1460+
},
1461+
isValidInteger(value) {
1462+
if (typeof value === 'boolean' || value === null || value === undefined) {
1463+
return false;
1464+
}
1465+
const str = String(value).trim();
1466+
if (str === '') {
1467+
return false;
1468+
}
1469+
const num = Number(str);
1470+
return Number.isInteger(num);
1471+
},
14491472
inspect(element = {}) {
14501473
this.closeTemplatesPanel();
14511474
this.inspection = element;

0 commit comments

Comments
 (0)