PluginProbe
The Innovative Form Builder – IvyForms / 0.8.2
The Innovative Form Builder – IvyForms v0.8.2
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 / public / fields / RatingFormField.vue

RatingFormField.vue in The Innovative Form Builder – IvyForms 0.8.2, at frontend/src/views/public/fields/RatingFormField.vue

80 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <template>
2 <div
3 :class="[
4 'ivyforms-field ivyforms-field__rating ivyforms-width-100',
5 'ivyforms-field__rating_' + field.id,
6 field.cssClasses,
7 ]"
8 >
9 <IvyFormItem
10 :label="field.hideLabel ? '' : field.label"
11 :required="field.required"
12 :error="error"
13 :prop="field.type + '_' + field.fieldIndex"
14 :show-info="!!field.description"
15 :info-text="field.description || ''"
16 :show-info-icon="false"
17 :label-position="field.labelPosition"
18 >
19 <IvyRating
20 :id="fieldID"
21 v-model="localModelValue"
22 :aria-label="field.label"
23 class="ivyforms-field__rating-input ivyforms-width-100"
24 :rating-icon="field.ratingIcon || 'star'"
25 :options="field.fieldOptions || []"
26 :disabled="disabled"
27 :show-label="field.showRatingText ?? false"
28 />
29 </IvyFormItem>
30 </div>
31 </template>
32
33 <script setup lang="ts">
34 import { computed, inject } from 'vue'
35 import type { Field } from '@/types/field'
36
37 interface FieldProps {
38 modelValue?: number | null
39 field: Field
40 disabled?: boolean
41 error?: string
42 }
43
44 const props = withDefaults(defineProps<FieldProps>(), {
45 modelValue: undefined,
46 disabled: false,
47 error: '',
48 })
49
50 const emit = defineEmits(['update:modelValue'])
51
52 // Inject clearFieldError function from parent
53 const clearFieldError = inject<(fieldKey: string) => void>('clearFieldError', () => {})
54
55 // Generate field key for clearing errors
56 const fieldKey = computed(() => {
57 return props.field.type + '_' + props.field.fieldIndex
58 })
59
60 // Handle input event to clear errors when user rates
61 const handleInput = (value: number | null | undefined) => {
62 emit('update:modelValue', value)
63 clearFieldError(fieldKey.value)
64 }
65
66 const localModelValue = computed({
67 get() {
68 return props.modelValue
69 },
70 set(value) {
71 handleInput(value)
72 },
73 })
74
75 // Generate unique field ID as a string
76 const fieldID = computed(() => {
77 return `ivyforms-field__rating-input_${props.field.formId || ''}_${props.field.fieldIndex || ''}`
78 })
79 </script>
80