diff --git a/src/Forms.vue b/src/Forms.vue index ed085e2..636c732 100644 --- a/src/Forms.vue +++ b/src/Forms.vue @@ -32,7 +32,7 @@ - + {{ t('forms', 'Loading forms …') }} @@ -102,16 +102,16 @@ export default { return this.forms && this.forms.length === 0 }, - hash() { + routeHash() { return this.$route.params.hash }, selectedForm: { get() { - return this.forms.find(form => form.hash === this.hash) + return this.forms.find(form => form.hash === this.routeHash) }, set(form) { - const index = this.forms.findIndex(search => search.hash === this.hash) + const index = this.forms.findIndex(search => search.hash === this.routeHash) if (index > -1) { this.$set(this.forms, index, form) } @@ -163,7 +163,14 @@ export default { */ async onDeleteForm(id) { const formIndex = this.forms.findIndex(form => form.id === id) + const deletedHash = this.forms[formIndex].hash + this.forms.splice(formIndex, 1) + + // Redirect if current form has been deleted + if (deletedHash === this.routeHash) { + this.$router.push({ name: 'root' }) + } }, }, } diff --git a/src/router.js b/src/router.js index 415c33c..2afc8c4 100644 --- a/src/router.js +++ b/src/router.js @@ -58,7 +58,7 @@ export default new Router({ path: '/:hash/results', component: Results, name: 'results', - props: { default: true }, + props: true, }, ], }) diff --git a/src/views/Results.vue b/src/views/Results.vue index 3315cc0..b95f36a 100644 --- a/src/views/Results.vue +++ b/src/views/Results.vue @@ -139,6 +139,13 @@ export default { }, }, + watch: { + // Reload results, when form changes + hash() { + this.loadFormResults() + }, + }, + beforeMount() { this.loadFormResults() SetWindowTitle(this.formTitle)