2020-11-09 01:24:19 +01:00
|
|
|
<template>
|
2022-09-21 21:38:53 +02:00
|
|
|
<div class="field" :class="{ 'pt-3' : hasOffset }" role="radiogroup" :aria-labelledby="inputId('label', fieldName)">
|
2023-02-08 15:56:00 +01:00
|
|
|
<label v-if="label" :id="inputId('label', fieldName)" class="label" v-html="label"></label>
|
2020-11-09 01:24:19 +01:00
|
|
|
<div class="is-toggle buttons">
|
2022-09-21 21:38:53 +02:00
|
|
|
<button
|
|
|
|
role="radio"
|
|
|
|
type="button"
|
2023-02-01 17:21:55 +01:00
|
|
|
class="button"
|
2022-09-21 21:38:53 +02:00
|
|
|
:aria-checked="form[fieldName] === choice.value"
|
|
|
|
:disabled="isDisabled"
|
|
|
|
v-for="(choice, index) in choices"
|
|
|
|
:key="index"
|
2023-02-01 17:21:55 +01:00
|
|
|
:class="{
|
|
|
|
'is-link' : form[fieldName] === choice.value,
|
2023-02-08 15:56:00 +01:00
|
|
|
'is-dark' : $root.showDarkMode,
|
|
|
|
'is-multiline' : choice.legend,
|
2023-02-01 17:21:55 +01:00
|
|
|
}"
|
2023-02-08 15:56:00 +01:00
|
|
|
v-on:click.stop="setRadio(choice.value)"
|
|
|
|
:title="choice.title ? choice.title : ''"
|
2022-09-21 21:38:53 +02:00
|
|
|
>
|
|
|
|
<input
|
|
|
|
:id="inputId(inputType, choice.value)"
|
|
|
|
:type="inputType"
|
|
|
|
class="is-hidden"
|
|
|
|
:checked="form[fieldName] === choice.value"
|
|
|
|
:value="choice.value"
|
|
|
|
v-model="form[fieldName]"
|
|
|
|
:disabled="isDisabled"
|
|
|
|
/>
|
2023-02-08 15:56:00 +01:00
|
|
|
<span v-if="choice.legend" v-html="choice.legend" class="is-block is-size-7"></span>
|
2020-11-19 14:07:31 +01:00
|
|
|
<font-awesome-icon :icon="['fas', choice.icon]" v-if="choice.icon" class="mr-3" /> {{ choice.text }}
|
2022-09-21 21:38:53 +02:00
|
|
|
</button>
|
2020-11-09 01:24:19 +01:00
|
|
|
</div>
|
|
|
|
<field-error :form="form" :field="fieldName" />
|
|
|
|
<p class="help" v-html="help" v-if="help"></p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'FormToggle',
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2022-09-21 21:38:53 +02:00
|
|
|
inputType: 'radio'
|
2020-11-09 01:24:19 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
label: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
|
|
|
|
fieldName: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
|
|
|
|
choices: {
|
|
|
|
type: Array,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
|
|
|
|
form: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
|
|
|
|
help: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
|
|
|
|
|
|
|
hasOffset: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2020-11-16 14:34:58 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
isDisabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2020-11-09 01:24:19 +01:00
|
|
|
}
|
2022-09-21 21:38:53 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
setRadio(event) {
|
|
|
|
this.form[this.fieldName] = event
|
|
|
|
this.$emit(this.fieldName, this.form[this.fieldName])
|
|
|
|
}
|
2020-11-09 01:24:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|