|
|
|
@ -1,28 +1,51 @@
|
|
|
|
|
<script lang="ts" setup> |
|
|
|
|
import type { VNodeRef } from '@vue/runtime-core' |
|
|
|
|
import { EditModeInj, computed, inject, useVModel, validateEmail } from '#imports' |
|
|
|
|
import { EditModeInj, computed, inject, useI18n, validateEmail } from '#imports' |
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
|
modelValue: string | null | undefined |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface Emits { |
|
|
|
|
(event: 'update:modelValue', model: string): void |
|
|
|
|
} |
|
|
|
|
const { modelValue: value } = defineProps<Props>() |
|
|
|
|
|
|
|
|
|
const props = defineProps<Props>() |
|
|
|
|
const emit = defineEmits(['update:modelValue']) |
|
|
|
|
|
|
|
|
|
const emits = defineEmits<Emits>() |
|
|
|
|
const { t } = useI18n() |
|
|
|
|
|
|
|
|
|
const { showNull } = useGlobal() |
|
|
|
|
|
|
|
|
|
const editEnabled = inject(EditModeInj) |
|
|
|
|
const editEnabled = inject(EditModeInj)! |
|
|
|
|
|
|
|
|
|
const column = inject(ColumnInj)! |
|
|
|
|
|
|
|
|
|
const vModel = useVModel(props, 'modelValue', emits) |
|
|
|
|
// Used in the logic of when to display error since we are not storing the email if it's not valid |
|
|
|
|
const localState = ref(value) |
|
|
|
|
|
|
|
|
|
const vModel = computed({ |
|
|
|
|
get: () => value, |
|
|
|
|
set: (val) => { |
|
|
|
|
localState.value = val |
|
|
|
|
if (!parseProp(column.value.meta)?.validate || (val && validateEmail(val)) || !val) { |
|
|
|
|
emit('update:modelValue', val) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const validEmail = computed(() => vModel.value && validateEmail(vModel.value)) |
|
|
|
|
|
|
|
|
|
const focus: VNodeRef = (el) => (el as HTMLInputElement)?.focus() |
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
|
() => editEnabled.value, |
|
|
|
|
() => { |
|
|
|
|
if (parseProp(column.value.meta)?.validate && !editEnabled.value && localState.value && !validateEmail(localState.value)) { |
|
|
|
|
message.error(t('msg.error.invalidEmail')) |
|
|
|
|
localState.value = undefined |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
localState.value = value |
|
|
|
|
}, |
|
|
|
|
) |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
|