PluginProbe
The Innovative Form Builder – IvyForms / 0.7
The Innovative Form Builder – IvyForms v0.7
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / frontend / src / views / admin / form-builder / fields / checkbox / CheckboxField.vue

CheckboxField.vue in The Innovative Form Builder – IvyForms 0.7, at frontend/src/views/admin/form-builder/fields/checkbox/CheckboxField.vue

111 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <template>
2 <div class="ivyforms-field__checkbox">
3 <IvyFormItem
4 :label="hideLabel ? '' : label"
5 :required="required"
6 :label-position="labelPosition"
7 >
8 <IvyCheckboxGroup
9 :id="index"
10 v-model="selectedValues"
11 readonly
12 class="ivyforms-field__checkbox-group ivyforms-flex ivyforms-align-items-start ivyforms-justify-content-start ivyforms-flex-direction-column ivyforms-gap-8"
13 >
14 <IvyCheckbox
15 v-for="option in checkboxOptions"
16 :id="option.id"
17 :key="option.id || option.value"
18 :value="option.value"
19 priority="secondary"
20 type="checkmark"
21 :class="['ivyforms-field__checkbox-option', { 'readonly-option': true }]"
22 >
23 {{ option.label }}
24 </IvyCheckbox>
25 </IvyCheckboxGroup>
26 <div v-if="description" class="ivyforms-description-message regular-14">
27 {{ description }}
28 </div>
29 </IvyFormItem>
30 </div>
31 </template>
32
33 <script setup lang="ts">
34 import { computed } from 'vue'
35 import { useFormBuilder } from '@/stores/useFormBuilder'
36 import IvyCheckbox from '@/views/_components/checkbox/IvyCheckbox.vue'
37 import IvyCheckboxGroup from '@/views/_components/checkbox/IvyCheckboxGroup.vue'
38 import IvyFormItem from '@/views/_components/form/IvyFormItem.vue'
39 import type { Choice } from '@/types/field'
40
41 const props = defineProps<{ fieldIndex: number }>()
42 const formBuilderStore = useFormBuilder()
43 const field = computed(() => formBuilderStore.fields.find((f) => f.fieldIndex === props.fieldIndex))
44 const label = computed(() => field.value?.label || '')
45 const required = computed(() => field.value?.required || false)
46 const hideLabel = computed(() => field.value?.hideLabel || false)
47 const index = computed(() => field.value?.fieldIndex ?? props.fieldIndex)
48 const description = computed(() => field.value?.description || '')
49
50 const labelPosition = computed(() =>
51 field.value?.labelPosition === 'default' ? 'top' : field.value?.labelPosition || 'top',
52 )
53
54 // Selected values derived only from isDefault flags
55 const selectedValues = computed<string[]>({
56 get() {
57 const opts = field.value?.fieldOptions || []
58 return opts.filter((opt) => opt.isDefault).map((opt) => opt.value)
59 },
60 set() {
61 /* no-op to block changes via UI */
62 },
63 })
64
65 // Helper to shuffle options if enabled
66 function shuffle(array: Choice[]) {
67 const arr = array.slice()
68 for (let i = arr.length - 1; i > 0; i--) {
69 const j = Math.floor(Math.random() * (i + 1))
70 ;[arr[i], arr[j]] = [arr[j], arr[i]]
71 }
72 return arr
73 }
74
75 const checkboxOptions = computed(() => {
76 let opts = field.value?.fieldOptions || []
77 if (field.value?.shuffleOptions) {
78 opts = shuffle(opts)
79 }
80 return opts.map((opt) => ({
81 label: opt.label,
82 value: opt.value,
83 id: opt.id,
84 }))
85 })
86 </script>
87
88 <style lang="scss" scoped>
89 .ivyforms-field__checkbox {
90 &-option {
91 color: var(--map-base-text-0);
92
93 &.readonly-option {
94 pointer-events: none;
95 cursor: default;
96 background: none;
97 }
98
99 &:hover {
100 background: none;
101 }
102 }
103 :deep(.el-checkbox__inner) {
104 background-color: transparent !important;
105 }
106 :deep(.ivyforms-form-item__label) {
107 cursor: default !important;
108 }
109 }
110 </style>
111