This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/frontend/src/components/forms/FormDialog.vue

67 lines
1.1 KiB
Vue
Raw Normal View History

2019-05-06 15:02:12 +00:00
<template>
<v-dialog v-model="dialog">
<v-btn slot="activator">
{{ buttonText }}
</v-btn>
<v-card>
<v-form
ref="form"
v-model="valid"
@submit.prevent="validate"
lazy-validation
>
<slot></slot>
<v-divider></v-divider>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="success" type="submit" :disabled="!valid">
{{ buttonText }}
</v-btn>
<v-btn color="error" @click="dialog = false">
Cancel
</v-btn>
</v-card-actions>
</v-form>
</v-card>
</v-dialog>
</template>
<script>
export default {
name: 'FormDialog',
data: () => ({
dialog: false,
valid: true
}),
props: {
buttonText: String
},
methods: {
validate() {
if (this.$refs.form.validate()) {
this.$parent.confirm()
}
}
},
watch: {
dialog(val) {
if (val) {
requestAnimationFrame(() => {
this.$parent.$refs.autofocus.focus()
})
} else {
this.$refs.form.resetValidation()
}
}
}
}
</script>