mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.3 KiB
82 lines
2.3 KiB
<script lang="ts" setup> |
|
import type { VNodeRef } from '@vue/runtime-core' |
|
import isMobilePhone from 'validator/lib/isMobilePhone' |
|
import { EditModeInj, IsExpandedFormOpenInj, IsSurveyFormInj, computed, inject } from '#imports' |
|
|
|
interface Props { |
|
modelValue: string | null | number | undefined |
|
isFocus?: boolean |
|
} |
|
|
|
const { modelValue: value, isFocus } = defineProps<Props>() |
|
|
|
const emit = defineEmits(['update:modelValue']) |
|
|
|
const rowHeight = inject(RowHeightInj, ref(undefined)) |
|
|
|
const { showNull } = useGlobal() |
|
|
|
const editEnabled = inject(EditModeInj)! |
|
|
|
const column = inject(ColumnInj)! |
|
|
|
// Used in the logic of when to display error since we are not storing the phone if it's not valid |
|
const localState = ref(value) |
|
|
|
const isSurveyForm = inject(IsSurveyFormInj, ref(false)) |
|
|
|
const vModel = computed({ |
|
get: () => value, |
|
set: (val) => { |
|
localState.value = val |
|
if (!parseProp(column.value.meta)?.validate || (val && isMobilePhone(val)) || !val || isSurveyForm.value) { |
|
emit('update:modelValue', val) |
|
} |
|
}, |
|
}) |
|
|
|
const validEmail = computed(() => vModel.value && isMobilePhone(vModel.value)) |
|
|
|
const isExpandedFormOpen = inject(IsExpandedFormOpenInj, ref(false))! |
|
|
|
const focus: VNodeRef = (el) => !isExpandedFormOpen.value && isFocus && (el as HTMLInputElement)?.focus() |
|
|
|
watch( |
|
() => editEnabled.value, |
|
() => { |
|
if (parseProp(column.value.meta)?.validate && !editEnabled.value && localState.value && !isMobilePhone(localState.value)) { |
|
message.error('Invalid Phone Number') |
|
localState.value = undefined |
|
return |
|
} |
|
localState.value = value |
|
}, |
|
) |
|
</script> |
|
|
|
<template> |
|
<input |
|
v-if="editEnabled" |
|
:ref="focus" |
|
v-model="vModel" |
|
class="w-full outline-none text-sm px-1 py-2" |
|
@blur="editEnabled = false" |
|
@keydown.down.stop |
|
@keydown.left.stop |
|
@keydown.right.stop |
|
@keydown.up.stop |
|
@keydown.delete.stop |
|
@keydown.ctrl.z.stop |
|
@keydown.meta.z.stop |
|
@selectstart.capture.stop |
|
@mousedown.stop |
|
/> |
|
|
|
<span v-else-if="vModel === null && showNull" class="nc-null">NULL</span> |
|
|
|
<a v-else-if="validEmail" class="text-sm underline hover:opacity-75" :href="`tel:${vModel}`" target="_blank"> |
|
<LazyCellClampedText :value="vModel" :lines="rowHeight" /> |
|
</a> |
|
|
|
<LazyCellClampedText v-else :value="vModel" :lines="rowHeight" /> |
|
</template>
|
|
|