Hi all,
I’m building a custom input (interface extension) to do some calculations behind the curtains before writing to DB and giving the user a feedback (it can’t be a hook).
Despite my zero knowledge of Vue, I was able to get some of it working. But there’s something that is not working no matter what: I cannot set the type of my input.
I need the resulted HTML to be of type “number”: <input ... type="number" />
but the type is always “string” (or “float” when I change the component options to types: ['float']
and the props value type to Number)
Here’s my code:
// index.ts
import { defineInterface } from "@directus/extensions-sdk";
import InterfaceComponent from "./interface.vue";
export default defineInterface({
id: "myInput",
name: "MyInput",
icon: "box",
description: "This is my custom interface!",
component: InterfaceComponent,
options: null,
types: ["float"],
});
// interface.vue
<template>
<VInput :model-value="dimension" @input="handleDimensionChange($event.target.value)" />
</template>
<script setup lang="ts">
import { ref, watch } from 'vue';
const emit = defineEmits(['input']);
const props = defineProps({
value: {
type: Number,
default: null,
},
});
const dimension = ref(props.value);
// observes when the value of props.value is actually received
// and updates the value of dimension (initially props.value is null)
// without this, the input doesn't show the persisted value
watch(() => props.value, () => {
dimension.value = props.value;
});
function handleDimensionChange(value: string): void {
emit('input', value);
}
</script>
I’ve tried adding type="number"
and :type="'number'"
to VInput with no success. It seems to work here though: VInput › default | Directus Components
p.s: As I said, I have zero knowledge of Vue (I’m used to React) so I believe that this may be a very silly question but I spent hours on it already.