2020-08-03 15:07:08 +02:00
|
|
|
<template>
|
2020-12-16 12:12:37 +01:00
|
|
|
<card v-bind="$attrs" class="card-form">
|
|
|
|
<template #default>
|
|
|
|
<slot name="disclaimer" />
|
|
|
|
|
|
|
|
<b-form
|
|
|
|
:id="id" :inline="inline" :class="formClasses"
|
|
|
|
@submit.prevent="onSubmit" novalidate
|
|
|
|
>
|
|
|
|
<slot name="default" />
|
|
|
|
|
|
|
|
<slot name="server-error">
|
|
|
|
<b-alert variant="danger" :show="serverError !== ''" v-html="serverError" />
|
|
|
|
</slot>
|
|
|
|
</b-form>
|
2020-10-23 17:46:07 +02:00
|
|
|
</template>
|
|
|
|
|
2020-12-16 12:36:45 +01:00
|
|
|
<slot v-if="!noFooter" name="buttons" slot="buttons">
|
2020-12-16 12:12:37 +01:00
|
|
|
<b-button
|
|
|
|
type="submit" variant="success"
|
|
|
|
:form="id" :disabled="disabled"
|
|
|
|
>
|
|
|
|
{{ submitText ? submitText : $t('save') }}
|
|
|
|
</b-button>
|
|
|
|
</slot>
|
|
|
|
</card>
|
2020-08-03 15:07:08 +02:00
|
|
|
</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
|
|
|
submitText: { type: String, default: null },
|
|
|
|
validation: { type: Object, default: null },
|
2020-12-16 12:12:37 +01:00
|
|
|
serverError: { type: String, default: '' },
|
|
|
|
inline: { type: Boolean, default: false },
|
2020-12-16 12:36:45 +01:00
|
|
|
formClasses: { type: [Array, String, Object], default: null },
|
|
|
|
noFooter: { type: Boolean, default: false }
|
2020-10-23 17:46:07 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
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">
|
|
|
|
</style>
|