Skip to content

Commit

Permalink
feat: initial form connection
Browse files Browse the repository at this point in the history
  • Loading branch information
davidruvolo51 committed Dec 10, 2024
1 parent 623c311 commit 660cf3a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
14 changes: 14 additions & 0 deletions apps/tailwind-components/components/form/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ function validate(value: columnValue) {
formFieldInput.value.validate(value);
}
const refData = ref();
onMounted(async () => {

This comment has been minimized.

Copy link
@connoratrug

connoratrug Dec 11, 2024

Contributor

it this fetching the options ? maybe we can move the trigger for this into the component type that needs it ( list box in this case ), and wrap the actual fetch into a composable for reuse

if (["ONTOLOGY", "ONTOLOGY_ARRAY"].includes(props.column.columnType)) {
const response = await fetchTableData(
props.column.refSchemaId as string,
props.column.refTableId as string
);
refData.value = response.rows.map((row) => row.name);
}
});
</script>

<template>
Expand All @@ -49,11 +61,13 @@ function validate(value: columnValue) {
{{ column.description }}
</div>
<div>
{{ column }}
<FormFieldInput
:type="column.columnType"
:id="column.id"
:label="column.label"
:data="data"
:options="refData ? refData : null"
:required="!!column.required"
:aria-invalid="hasError"
:aria-desribedBy="`${column.id}-input-error`"
Expand Down
20 changes: 18 additions & 2 deletions apps/tailwind-components/components/form/FieldInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import type {
InputString,
InputTextArea,
InputPlaceHolder,
InputListbox,
} from "#build/components";
import type {
columnId,
columnValue,
CellValueType,
} from "../../../metadata-utils/src/types";
import type { IListboxValue } from "~/types/listbox";
type inputComponent =
| InstanceType<typeof InputString>
| InstanceType<typeof InputTextArea>
Expand All @@ -21,6 +24,7 @@ defineProps<{
label: string;
required: boolean;
data: columnValue;
options?: IListboxValue[];
}>();
defineEmits(["focus", "error", "update:modelValue"]);
Expand All @@ -47,7 +51,7 @@ function validate(value: columnValue) {
:id="id"
:label="label"
:required="required"
:value="data as string"
:value="(data as string)"
@focus="$emit('focus')"
@update:modelValue="$emit('update:modelValue', $event)"
@error="$emit('error', $event)"
Expand All @@ -58,10 +62,22 @@ function validate(value: columnValue) {
:id="id"
:label="label"
:required="required"
:value="data as string"
:value="(data as string)"
@focus="$emit('focus')"
@update:modelValue="$emit('update:modelValue', $event)"
@error="$emit('error', $event)"
></LazyInputTextArea>
<template
v-else-if="['ONTOLOGY', 'ONTOLOGY_ARRAY'].includes(type) && options"
>
<LazyInputListbox
ref="input"
:id="id"
:label-id="id"
:required="required"
:options="options"
:placeholder="`Select a ${id}`"
/>
</template>
<LazyInputPlaceHolder v-else ref="input" :type="type" />
</template>

0 comments on commit 660cf3a

Please sign in to comment.