mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
update BasicForm to receive validations object and some base behavior
This commit is contained in:
parent
4512962412
commit
2e13bcd8bd
1 changed files with 42 additions and 8 deletions
|
@ -1,13 +1,26 @@
|
||||||
<template>
|
<template>
|
||||||
<b-card :header="header" header-tag="h2" class="basic-form">
|
<b-card class="basic-form">
|
||||||
<b-form :id="id" @submit="$emit('submit', $event)">
|
<template v-slot:header>
|
||||||
<slot />
|
<h2><icon v-if="icon" :iname="icon" /> {{ title }}</h2>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<slot name="disclaimer"></slot>
|
||||||
|
|
||||||
|
<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>
|
||||||
</b-form>
|
</b-form>
|
||||||
|
|
||||||
<template v-if="!noFooter" v-slot:footer>
|
<template v-if="!noFooter" v-slot:footer>
|
||||||
<slot name="buttons">
|
<slot name="buttons">
|
||||||
<b-button type="submit" :form="id" variant="success">
|
<b-button
|
||||||
{{ submit ? submit : $t('save') }}
|
type="submit" variant="success"
|
||||||
|
:form="id" :disabled="disabled"
|
||||||
|
>
|
||||||
|
{{ submitText ? submitText : $t('save') }}
|
||||||
</b-button>
|
</b-button>
|
||||||
</slot>
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
|
@ -15,14 +28,35 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'BasicForm',
|
name: 'BasicForm',
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
header: { type: String, required: true },
|
|
||||||
id: { type: String, default: 'ynh-form' },
|
id: { type: String, default: 'ynh-form' },
|
||||||
submit: { type: String, default: null },
|
title: { type: String, required: true },
|
||||||
noFooter: { type: Boolean, default: false }
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue