You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
docuseal/app/javascript/submission_form/multi_select_step.vue

103 lines
2.3 KiB

<template>
<label
v-if="field.name"
:for="field.uuid"
dir="auto"
class="label text-2xl mb-2"
>{{ field.name }}</label>
<div class="flex w-full">
<input
v-if="modelValue.length === 0"
type="text"
:name="`values[${field.uuid}][]`"
:value="''"
class="hidden"
>
<div
v-if="field.options.length > 5"
class="text-xl text-center w-full"
>
<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"
:class="{ hidden: field.options.length > 5 }"
>
<div
v-for="(option, index) in field.options"
:key="option.uuid"
>
<label
:for="option.uuid"
class="flex items-center space-x-3"
>
<input
:id="option.uuid"
:ref="setInputRef"
type="checkbox"
:name="`values[${field.uuid}][]`"
:value="optionValue(option, index)"
class="base-checkbox !h-7 !w-7"
:checked="(modelValue || []).includes(optionValue(option, index))"
@change="onChange"
>
<span class="text-xl">
{{ optionValue(option, index) }}
</span>
</label>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'MultiSelectStep',
inject: ['t', 'scrollIntoField'],
props: {
field: {
type: Object,
required: true
},
isLastStep: {
type: Boolean,
required: true,
default: false
},
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)
}
},
optionValue (option, index) {
if (option.value) {
return option.value
} else {
return `${this.t('option')} ${index + 1}`
}
},
onChange () {
this.$emit('update:model-value', this.inputRefs.filter(e => e.checked).map((e, index) => this.optionValue(e, index)))
}
}
}
</script>