Skip to content

Commit

Permalink
Update order property
Browse files Browse the repository at this point in the history
  • Loading branch information
caleeli committed Mar 5, 2024
1 parent 4f491d3 commit 49dac5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/components/sortable/sortableList/SortableList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ export default {
},
methods: {
validateState(name, item) {
const isEmpty = !name;
const isEmpty = !name?.trim();
const isDuplicated = this.items
.filter((i) => i !== item)
.find((i) => i.name === name);
return isEmpty || isDuplicated ? false : null;
},
validateError(name, item) {
const isEmpty = !name;
const isEmpty = !name?.trim();
if (!isEmpty) {
return this.$t("The Page Name field is required.");
}
Expand Down Expand Up @@ -162,6 +162,14 @@ export default {
itemsSortedClone[draggedItemIndex].order = tempOrder;
}
// Update order of the items
const clone = [...itemsSortedClone];
clone.sort((a, b) => a.order - b.order);
clone.forEach((item, index) => {
// eslint-disable-next-line no-param-reassign
item.order = index + 1;
});
}
this.$emit('ordered', itemsSortedClone);
Expand Down
14 changes: 14 additions & 0 deletions src/components/vue-form-builder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ export default {
config.forEach((page) => this.replaceFormText(page.items));
config.forEach((page) => this.migrateFormSubmit(page.items));
config.forEach((page) => this.updateFieldNameValidation(page.items));
this.updatePageOrder(config);
config.forEach((page) =>
this.removeDataVariableFromNestedScreens(page.items)
);
Expand All @@ -889,6 +890,18 @@ export default {
page.order = page.order || index + 1;
});
},
updatePageOrder(pages) {
const clone = [...pages];
clone.sort((a, b) => {
const aOrder = a.order || pages.indexOf(a) + 1;
const bOrder = b.order || pages.indexOf(b) + 1;
return aOrder - bOrder;
});
clone.forEach((item, index) => {
// eslint-disable-next-line no-param-reassign
item.order = index + 1;
});
},
updateFieldNameValidation(items) {
items.forEach((item) => {
if (item.inspector) {
Expand Down Expand Up @@ -1227,6 +1240,7 @@ export default {
globalObject.ProcessMaker.alert(error.message, "danger");
return;
}
this.updatePageOrder(this.config);
this.$store.dispatch("undoRedoModule/pushState", {
config: JSON.stringify(this.config),
currentPage: this.currentPage,
Expand Down

0 comments on commit 49dac5a

Please sign in to comment.