diff --git a/ayanova/src/views/inventory-widget-edit.vue b/ayanova/src/views/inventory-widget-edit.vue index 246fd761..6ed964d7 100644 --- a/ayanova/src/views/inventory-widget-edit.vue +++ b/ayanova/src/views/inventory-widget-edit.vue @@ -293,7 +293,7 @@ export default { this.$gzevent.$on("menu-click", clickHandler); //id 0 means create a new record don't load one if (this.$route.params.id != 0) { - this.getDataFromApi(); + this.getDataFromApi(this.$route.params.id); } else { // console.log("CREATED: setting up for new record"); // console.log("CREATED: Rights are:"); @@ -319,6 +319,15 @@ export default { generateMenu(this); } }, + beforeRouteUpdate(to, from, next) { + //fetch the data for the record as if it's a new record + if (to.params.id != 0) { + this.getDataFromApi(to.params.id); + } + next(); + // react to route changes... + // don't forget to call next() + }, beforeRouteLeave(to, from, next) { var vm = this; if (this.formState.dirty && !JUST_DELETED) { @@ -439,9 +448,12 @@ export default { this.$gzform.onChange(this, ref); } }, - getDataFromApi() { + getDataFromApi(recordId) { this.formState.loading = true; - var url = "Widget/" + this.$route.params.id; + if (!recordId) { + throw "inventory-widget-edit::getDataFromApi -> Missing recordID!"; + } + var url = "Widget/" + recordId; var vm = this; this.$gzform.deleteAllErrorBoxErrors(this); @@ -585,7 +597,7 @@ export default { vm.$gzform.setErrorBoxErrors(vm); } else { //Navigate to new record - bugbug: this is not navigating, only changing the url in the location bar?? + vm.$router.push( vm.$gzapi.replaceAfterLastSlash(vm.$route.fullPath, res.data.id) );