Skip to content

Commit d77a65a

Browse files
authored
Merge pull request #77 from cividi/fix/snapshot-upload-form-validation
Fix: Snapshot upload form validation
2 parents 273edfb + 481e02a commit d77a65a

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

vue/src/components/SnapshotEdit.vue

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
ref="snapshotform"
5757
v-model="valid"
5858
lazy-validation
59+
@submit="saveSnapshot"
5960
>
6061
<v-text-field
6162
v-model="selected.title"
@@ -81,7 +82,9 @@
8182
return-object
8283
required
8384
@update:search-input="queryAndSetMunicipalities"
84-
:rules="[(value) => value && value.bfsNumber ? true : $t('municipalityMandatory')]"
85+
:rules="[
86+
(municipality) => municipality && municipality.bfsNumber || $t('municipalityMandatory')
87+
]"
8588
:hide-no-data="!municipalities.length"
8689
>
8790
<v-list-item slot="no-data">
@@ -95,7 +98,11 @@
9598
accept=".json"
9699
:label="$t('file')"
97100
truncate-length="20"
98-
:rules="[v => !!v || $t('mandatory')]"
101+
:rules="[
102+
file => !!snapshot.datafile ||
103+
!!(file && file.name && file.type === 'application/json') ||
104+
$t('mandatory')
105+
]"
99106
:required="isNew"
100107
@change="selectFile"
101108
>
@@ -119,8 +126,8 @@
119126
{{ $t('cancel') }}
120127
</v-btn>
121128
<v-btn
122-
color="primary"
123-
@click="saveSnapshot"
129+
type="submit"
130+
color="primary"
124131
>
125132
{{ $t('save') }}
126133
</v-btn>
@@ -212,7 +219,8 @@ export default {
212219
});
213220
return data.municipalities.edges.map(({ node }) => node);
214221
},
215-
async saveSnapshot() {
222+
async saveSnapshot(event) {
223+
event.preventDefault();
216224
if (!this.$refs.snapshotform.validate()) {
217225
return;
218226
}

0 commit comments

Comments
 (0)