Files
docuseal/app/javascript/submission_form/multi_select_step.vue
T

87 lines
1.8 KiB
Vue
Raw Normal View History

2023-05-25 22:47:52 +03:00
<template>
2023-06-15 01:05:04 +03:00
<label
v-if="field.name"
:for="field.uuid"
2024-01-07 14:19:21 +02:00
dir="auto"
2023-06-15 01:05:04 +03:00
class="label text-2xl mb-2"
>{{ field.name }}</label>
2023-06-16 00:04:05 +03:00
<div class="flex w-full">
2024-01-06 15:05:15 +02:00
<input
v-if="modelValue.length === 0"
type="text"
:name="`values[${field.uuid}][]`"
:value="''"
class="hidden"
>
2023-06-16 00:04:05 +03:00
<div class="space-y-3.5 mx-auto">
<div
2024-01-06 15:05:15 +02:00
v-for="(option, index) in field.options"
2023-11-13 01:46:28 +02:00
:key="option.uuid"
2023-05-25 22:47:52 +03:00
>
2023-06-16 00:04:05 +03:00
<label
2023-11-13 01:46:28 +02:00
:for="option.uuid"
2023-06-16 00:04:05 +03:00
class="flex items-center space-x-3"
2023-06-15 01:05:04 +03:00
>
2023-06-16 00:04:05 +03:00
<input
2023-11-13 01:46:28 +02:00
:id="option.uuid"
2023-06-16 00:04:05 +03:00
:ref="setInputRef"
type="checkbox"
:name="`values[${field.uuid}][]`"
2024-01-06 15:05:15 +02:00
:value="optionValue(option, index)"
2023-06-16 00:04:05 +03:00
class="base-checkbox !h-7 !w-7"
2024-01-06 15:05:15 +02:00
:checked="(modelValue || []).includes(optionValue(option, index))"
2023-06-16 00:04:05 +03:00
@change="onChange"
>
<span class="text-xl">
2024-01-06 15:05:15 +02:00
{{ optionValue(option, index) }}
2023-06-16 00:04:05 +03:00
</span>
</label>
</div>
2023-06-15 01:05:04 +03:00
</div>
2023-05-25 22:47:52 +03:00
</div>
</template>
2023-06-15 01:05:04 +03:00
2023-05-25 22:47:52 +03:00
<script>
export default {
2023-06-16 00:04:05 +03:00
name: 'MultiSelectStep',
2024-01-06 15:05:15 +02:00
inject: ['t'],
2023-05-25 22:47:52 +03:00
props: {
field: {
type: Object,
required: true
},
modelValue: {
type: Array,
required: false,
default: () => []
}
},
emits: ['update:model-value'],
data () {
return {
inputRefs: []
}
},
beforeUpdate () {
this.inputRefs = []
},
methods: {
setInputRef (el) {
if (el) {
this.inputRefs.push(el)
}
},
2024-01-06 15:05:15 +02:00
optionValue (option, index) {
if (option.value) {
return option.value
} else {
return `${this.t('option')} ${index + 1}`
}
},
2023-05-25 22:47:52 +03:00
onChange () {
2024-01-06 15:05:15 +02:00
this.$emit('update:model-value', this.inputRefs.filter(e => e.checked).map((e, index) => this.optionValue(e, index)))
2023-05-25 22:47:52 +03:00
}
}
}
</script>