2020-08-03 15:07:08 +02:00
|
|
|
<template>
|
2020-10-28 16:49:43 +01:00
|
|
|
<b-card class="card-form">
|
2020-10-23 17:46:07 +02:00
|
|
|
<template v-slot:header>
|
2020-11-01 17:03:06 +01:00
|
|
|
<component :is="titleTag"><icon v-if="icon" :iname="icon" /> {{ title }}</component>
|
2020-10-23 17:46:07 +02:00
|
|
|
</template>
|
|
|
|
|
2020-11-01 17:03:06 +01:00
|
|
|
<slot name="disclaimer" />
|
2020-10-23 17:46:07 +02:00
|
|
|
|
|
|
|
<b-form :id="id" @submit.prevent="onSubmit" novalidate>
|
|
|
|
<slot name="default" />
|
|
|
|
|
|
|
|
<slot name="server-error">
|
|
|
|
<b-alert variant="danger" :show="serverError !== ''" v-html="serverError" />
|
|
|
|
</slot>
|
2020-08-03 15:07:08 +02:00
|
|
|
</b-form>
|
|
|
|
|
2020-09-13 17:35:32 +02:00
|
|
|
<template v-if="!noFooter" v-slot:footer>
|
2020-08-03 15:07:08 +02:00
|
|
|
<slot name="buttons">
|
2020-10-23 17:46:07 +02:00
|
|
|
<b-button
|
|
|
|
type="submit" variant="success"
|
|
|
|
:form="id" :disabled="disabled"
|
|
|
|
>
|
|
|
|
{{ submitText ? submitText : $t('save') }}
|
2020-08-03 15:07:08 +02:00
|
|
|
</b-button>
|
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
</b-card>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-10-23 17:46:07 +02:00
|
|
|
|
2020-08-03 15:07:08 +02:00
|
|
|
export default {
|
2020-10-28 16:49:43 +01:00
|
|
|
name: 'CardForm',
|
2020-08-03 15:07:08 +02:00
|
|
|
|
|
|
|
props: {
|
|
|
|
id: { type: String, default: 'ynh-form' },
|
2020-10-23 17:46:07 +02:00
|
|
|
title: { type: String, required: true },
|
2020-11-01 17:03:06 +01:00
|
|
|
titleTag: { type: String, default: 'h2' },
|
2020-10-23 17:46:07 +02:00
|
|
|
icon: { type: String, default: null },
|
|
|
|
submitText: { type: String, default: null },
|
|
|
|
noFooter: { type: Boolean, default: false },
|
|
|
|
validation: { type: Object, default: null },
|
|
|
|
serverError: { type: String, default: '' }
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
disabled () {
|
|
|
|
return this.validation ? this.validation.$invalid : false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
onSubmit (e) {
|
|
|
|
const v = this.validation
|
|
|
|
if (v) {
|
|
|
|
v.$touch()
|
|
|
|
if (v.$pending || v.$invalid) return
|
|
|
|
}
|
|
|
|
this.$emit('submit', e)
|
|
|
|
}
|
2020-08-03 15:07:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2020-10-28 16:49:43 +01:00
|
|
|
.card-form .card-footer {
|
2020-08-03 15:07:08 +02:00
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
|
|
|
& > *:not(:first-child) {
|
|
|
|
margin-left: .5rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|