|
| 1 | +<template> |
| 2 | + <input |
| 3 | + :id="cell.id + '-input'" |
| 4 | + v-model="dataTime" |
| 5 | + type="datetime-local" |
| 6 | + :class="styles.control.input" |
| 7 | + :disabled="!cell.enabled" |
| 8 | + :autofocus="appliedOptions.focus" |
| 9 | + :placeholder="appliedOptions.placeholder" |
| 10 | + @change="onChange" |
| 11 | + @focus="isFocused = true" |
| 12 | + @blur="isFocused = false" |
| 13 | + /> |
| 14 | +</template> |
| 15 | + |
| 16 | +<script setup lang="ts"> |
| 17 | +import { ref, watch } from 'vue'; |
| 18 | +import { useJsonFormsCell } from '@jsonforms/vue'; |
| 19 | +import type { CellProps, RankedTester } from '@jsonforms/core'; |
| 20 | +import { isDateTimeControl, rankWith } from '@jsonforms/core'; |
| 21 | +import { useVanillaCell } from '../util'; |
| 22 | +
|
| 23 | +const props = defineProps<CellProps>(); |
| 24 | +
|
| 25 | +const input = useVanillaCell(useJsonFormsCell(props), (target) => |
| 26 | + '' !== target.value ? toISO(target.value) : undefined |
| 27 | +); |
| 28 | +const { styles, cell, appliedOptions, onChange, isFocused } = input; |
| 29 | +
|
| 30 | +const fromISO = (str: string | undefined) => str?.slice(0, 16); |
| 31 | +const toISO = (str: string) => str + ':00.000Z'; |
| 32 | +
|
| 33 | +const dataTime = ref(); |
| 34 | +const setDateTime = (str: string | undefined) => { |
| 35 | + dataTime.value = fromISO(str); |
| 36 | +}; |
| 37 | +
|
| 38 | +setDateTime(props.data.value); |
| 39 | +watch(() => props.data, setDateTime); |
| 40 | +
|
| 41 | +defineOptions({ |
| 42 | + tester: rankWith(2, isDateTimeControl) as RankedTester, |
| 43 | +}); |
| 44 | +</script> |
0 commit comments