Add form validation

This commit is contained in:
Björn Fromme
2018-11-27 11:36:02 +01:00
parent 60c76dc717
commit b641c3211f
@@ -108,7 +108,16 @@
data () {
return {
picker: null,
address: {}
address: {},
requiredFields: [
{ field: 'name', label: 'Name' },
{ field: 'firstName', label: 'Vorname' },
{ field: 'street', label: 'Straße' },
{ field: 'zipCode', label: 'PLZ' },
{ field: 'city', label: 'Stadt' },
{ field: 'country', label: 'Land' },
{ field: 'email', label: 'E-Mail' }
]
}
},
created () {
@@ -136,6 +145,17 @@
});
},
saveAddress () {
for (const entry of this.requiredFields)
{
if (!this.address[entry.field]) {
this.$store.commit('alert', {
message: 'Bitte das Feld "' + entry.label + '" ausfüllen',
class: 'alert-danger'
});
EventBus.$emit('scrollTo', '#myep-main');
return false;
}
}
this.$store.dispatch('address/save', this.address)
.then(() => {
EventBus.$emit('scrollTo', '#myep-main');