1+ <template>
2+ <RockFormField v-bind="fieldProps" :modelValue="formFieldValue" name="group-drop-down" :disabled="disabled">
3+ <BaseAsyncPicker
4+ v-model="internalValue"
5+ v-bind="standardProps"
6+ :label="label"
7+ :items="groupItems"
8+ :multiple="false"
9+ :disabled="disabled"
10+ showBlankItem
11+ rules=""
12+ :displayStyle="PickerDisplayStyle.Condensed" />
13+ </RockFormField>
14+ </template>
15+
16+ <script setup lang="ts">
17+ import { computed } from "vue";
18+ import { useHttp } from "@Obsidian/Utility/http";
19+ import { PickerDisplayStyle } from "@Obsidian/Enums/Controls/pickerDisplayStyle";
20+ import RockFormField from "./rockFormField.obs";
21+ import BaseAsyncPicker from "./baseAsyncPicker.obs";
22+ import { ListItemBag } from "@Obsidian/ViewModels/Utility/listItemBag";
23+ import { useVModelPassthrough } from "@Obsidian/Utility/component";
24+ import {
25+ useStandardRockFormFieldProps,
26+ useStandardAsyncPickerProps,
27+ standardAsyncPickerProps
28+ } from "@Obsidian/Utility/component";
29+
30+ const props = defineProps({
31+ modelValue: {
32+ type: Object as () => ListItemBag | null,
33+ default: null
34+ },
35+
36+ includeInactive: {
37+ type: Boolean,
38+ default: false
39+ },
40+
41+ disabled: {
42+ type: Boolean,
43+ default: false
44+ },
45+
46+ ...standardAsyncPickerProps
47+ });
48+
49+ const emit = defineEmits(["update:modelValue"]);
50+
51+ const http = useHttp();
52+ const fieldProps = useStandardRockFormFieldProps(props);
53+ const standardProps = useStandardAsyncPickerProps(props);
54+ const internalValue = useVModelPassthrough(props, "modelValue", emit);
55+
56+ const formFieldValue = computed(() => internalValue.value);
57+
58+ const groupItems = async (): Promise<ListItemBag[]> => {
59+ const response = await http.get<Array<{ guid: string, name: string, isActive: boolean }>>(
60+ `/api/v2/Controls/GroupList?includeInactive=${props.includeInactive}`
61+ );
62+
63+ if (response.isSuccess && response.data) {
64+ return response.data.map(g => ({
65+ text: `${g.name}${g.isActive === false ? " (Inactive)" : ""}`,
66+ value: g.guid
67+ }));
68+ }
69+
70+ console.error(response.errorMessage ?? "Error loading group list.");
71+ return [];
72+ };
73+ </script>
0 commit comments