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

138 lines
3.2 KiB
Vue
Raw Normal View History

2023-05-25 22:47:52 +03:00
<template>
2023-06-15 01:05:04 +03:00
<label
2024-03-09 18:24:21 +02:00
v-if="showFieldNames && (field.name || field.title)"
2023-06-15 01:05:04 +03:00
:for="field.uuid"
2024-01-07 14:19:21 +02:00
dir="auto"
2025-02-02 12:30:01 +02:00
class="label text-xl sm:text-2xl py-0 mb-2 sm:mb-3.5"
2024-03-09 18:24:21 +02:00
:class="{ 'mb-2': !field.description }"
>
<MarkdownContent
v-if="field.title"
:string="field.title"
/>
2024-03-09 18:24:21 +02:00
<template v-else>{{ field.name }}</template>
<template v-if="!field.required">
2025-02-02 12:30:01 +02:00
<span :class="{ 'hidden sm:inline': (field.title || field.name).length > 20 }">
({{ t('optional') }})
</span>
</template>
2024-03-09 18:24:21 +02:00
</label>
<div
v-if="field.description"
dir="auto"
class="mb-3 px-1"
>
<MarkdownContent :string="field.description" />
</div>
2024-01-24 23:20:53 +02:00
<div class="flex w-full max-h-44 overflow-y-auto">
2024-01-06 15:05:15 +02:00
<input
v-if="modelValue.length === 0"
type="text"
:name="`values[${field.uuid}][]`"
:value="''"
class="hidden"
>
2024-01-24 22:28:45 +02:00
<div
2024-01-24 23:20:53 +02:00
v-if="!showOptions"
class="text-xl px-1"
2024-01-24 22:28:45 +02:00
>
<span @click="scrollIntoField(field)">
{{ t('complete_hightlighted_checkboxes_and_click') }} <span class="font-semibold">{{ isLastStep ? t('submit') : t('next') }}</span>.
</span>
</div>
<div
class="space-y-3.5 mx-auto"
2024-01-24 23:20:53 +02:00
:class="{ hidden: !showOptions }"
2024-01-24 22:28:45 +02:00
>
2023-06-16 00:04:05 +03:00
<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"
2024-03-29 21:43:13 +02:00
@click="scrollIntoField(field)"
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>
2024-03-09 18:24:21 +02:00
import MarkdownContent from './markdown_content'
2023-05-25 22:47:52 +03:00
export default {
2023-06-16 00:04:05 +03:00
name: 'MultiSelectStep',
2024-03-09 18:24:21 +02:00
components: {
MarkdownContent
},
2024-01-24 22:28:45 +02:00
inject: ['t', 'scrollIntoField'],
2023-05-25 22:47:52 +03:00
props: {
field: {
type: Object,
required: true
},
2024-01-24 22:28:45 +02:00
isLastStep: {
type: Boolean,
required: true,
default: false
},
2024-01-24 23:20:53 +02:00
showFieldNames: {
type: Boolean,
required: false,
default: true
},
2023-05-25 22:47:52 +03:00
modelValue: {
type: Array,
required: false,
default: () => []
}
},
emits: ['update:model-value'],
data () {
return {
inputRefs: []
}
},
2024-01-24 23:20:53 +02:00
computed: {
showOptions () {
return this.showFieldNames && (this.field.options.some((e) => e.value) || this.field.options.length < 5)
}
},
2023-05-25 22:47:52 +03:00
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>