1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
<!--
Matomo - free/libre analytics platform
@link https://matomo.org
@license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
-->
<template>
<FormField
:form-field="field"
:model-value="modelValue"
@update:model-value="onChange($event)"
>
<template v-slot:inline-help>
<slot name="inline-help"></slot>
</template>
</FormField>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import FormField from '../FormField/FormField.vue';
const UI_CONTROLS_TO_TYPE: Record<string, string> = {
multiselect: 'array',
checkbox: 'boolean',
site: 'object',
number: 'integer',
};
export default defineComponent({
props: {
modelValue: null,
uicontrol: String,
name: String,
defaultValue: null,
options: [Object, Array],
description: String,
introduction: String,
title: String,
inlineHelp: [String, Object],
inlineHelpBind: Object,
disabled: Boolean,
uiControlAttributes: {
type: Object,
default: () => ({}),
},
uiControlOptions: {
type: Object,
default: () => ({}),
},
autocomplete: Boolean,
condition: Function,
varType: String,
autofocus: Boolean,
tabindex: Number,
fullWidth: Boolean,
maxlength: Number,
required: Boolean,
placeholder: String,
rows: Number,
min: Number,
max: Number,
component: null,
templateFile: String,
},
emits: ['update:modelValue'],
components: {
FormField,
},
computed: {
type() {
if (this.varType) {
return this.varType;
}
const uicontrol = this.uicontrol as string;
if (uicontrol && UI_CONTROLS_TO_TYPE[uicontrol]) {
return UI_CONTROLS_TO_TYPE[uicontrol];
}
return 'string';
},
field() {
return {
uiControl: this.uicontrol,
type: this.type,
name: this.name,
defaultValue: this.defaultValue,
availableValues: this.options,
description: this.description,
introduction: this.introduction,
inlineHelp: this.inlineHelp,
inlineHelpBind: this.inlineHelpBind,
title: this.title,
component: this.component,
templateFile: this.templateFile, // BC for angularjs code that uses <Field> indirectly
uiControlAttributes: {
...this.uiControlAttributes,
disabled: this.disabled,
autocomplete: this.autocomplete,
tabindex: this.tabindex,
autofocus: this.autofocus,
rows: this.rows,
required: this.required,
maxlength: this.maxlength,
placeholder: this.placeholder,
min: this.min,
max: this.max,
},
fullWidth: this.fullWidth,
uiControlOptions: this.uiControlOptions,
};
},
},
methods: {
onChange(newValue: unknown) {
this.$emit('update:modelValue', newValue);
},
},
});
</script>
|