Add form validation
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user