This commit is contained in:
2020-06-22 16:50:48 +00:00
parent 0c66765bf1
commit d8ae4f43f8
2 changed files with 10 additions and 3 deletions

View File

@@ -233,6 +233,7 @@
const FORM_KEY = "user-edit";
const API_BASE_URL = "user/";
const FORM_CUSTOM_TEMPLATE_KEY = "User";
let InternalRouteChange = false;
export default {
async created() {
@@ -245,6 +246,7 @@ export default {
window.$gz.eventBus.$on("menu-click", clickHandler);
//id 0 means create a new record don't load one
if (vm.$route.params.recordid != 0) {
console.trace("created, calling get data from api irc=",InternalRouteChange)
vm.getDataFromApi(vm.$route.params.recordid);
} else {
//setup for new record
@@ -267,12 +269,16 @@ export default {
beforeRouteUpdate(to, from, next) {
//This triggers a fetch of the data when the ID value changes on the route
//which happens on duplicate, submit new record and change of active record id (backward nav/forward nav etc)
if (to.params.recordid != 0) {
console.trace("beforeRouteUpdate irc=",InternalRouteChange)
if (!InternalRouteChange && to.params.recordid != 0) {
console.trace("beforeRouteUpdate, calling get data from api irc=",InternalRouteChange)
this.getDataFromApi(to.params.recordid);
}
next();
// react to route changes...
// don't forget to call next()
//reset flag
InternalRouteChange = false;
},
async beforeRouteLeave(to, from, next) {
if (!this.formState.dirty || JUST_DELETED) {
@@ -469,6 +475,7 @@ export default {
//change url to new record in history
//NOTE: will not cause a page re-render, almost nothing does unless forced with a KEY property or using router.GO()
//but will trigger navigation guard beforeRouteUpdate which we use here in this form to fetch data freshly
InternalRouteChange = true;
vm.$router.replace(vm.$route.fullPath.slice(0, -1) + res.data.id);
} else {
//Handle "put" of an existing record (UPDATE)
@@ -576,7 +583,7 @@ async function clickHandler(menuItem) {
break;
case "new":
m.vm.$router.push({
name: "user-edit",
name: "adm-usr",
params: { recordid: 0, new: true }
});
break;