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

91 lines
1.7 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-snackbar v-model="snackbar.visible" :timeout="6000" :color="snackbar.color" absolute top>
{{ snackbar.text }}
<v-btn @click.native="snackbar.visible = false" fab flat icon>
2019-05-08 19:34:40 +00:00
<v-icon>close</v-icon>
</v-btn>
</v-snackbar>
2019-05-06 15:02:12 +00:00
<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>
2019-05-07 20:14:23 +00:00
<v-btn color="error" @click.native="dialog = false">
Close
2019-05-06 15:02:12 +00:00
</v-btn>
</v-card-actions>
</v-form>
</v-card>
</v-dialog>
</template>
<script>
export default {
name: 'FormDialog',
data: () => ({
dialog: false,
2019-05-08 19:34:40 +00:00
valid: true,
snackbar: {
visible: false,
color: '',
text: ''
}
2019-05-06 15:02:12 +00:00
}),
props: {
buttonText: String
},
methods: {
validate() {
if (this.$refs.form.validate()) {
2019-05-08 20:55:15 +00:00
this.$emit('validated')
2019-05-06 15:02:12 +00:00
}
2019-05-08 19:34:40 +00:00
},
showSnackbar(text, color) {
if (text == '') return
2019-05-08 19:34:40 +00:00
this.snackbar.visible = false
window.setTimeout(() => {
this.snackbar.text = text
this.snackbar.color = color
this.snackbar.visible = true
}, 100)
2019-05-06 15:02:12 +00:00
}
},
watch: {
dialog(val) {
if (val) {
requestAnimationFrame(() => {
this.$parent.$refs.autofocus.focus()
})
} else {
this.$refs.form.resetValidation()
}
}
}
}
</script>