Skip to content

Commit e23b8ac

Browse files
committed
refactor: Add intl-tel-input package for phone number input
1 parent 70149cd commit e23b8ac

File tree

5 files changed

+104
-3
lines changed

5 files changed

+104
-3
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@vueuse/core": "^10.6.1",
2929
"crypto-js": "^4.2.0",
3030
"http2-proxy": "^5.0.53",
31+
"intl-tel-input": "^24.4.0",
3132
"remixicon": "^3.5.0",
3233
"socket.io-client": "^4.7.2",
3334
"vue": "^3.4.18",
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<script setup lang="ts">
2+
import { useVModel } from '@vueuse/core'
3+
import intlTelInput from 'intl-tel-input/intlTelInputWithUtils'
4+
import { onMounted, onUnmounted, ref } from 'vue'
5+
6+
import useValidationModel from '../../composables/useValidationModel'
7+
8+
import BasicFormGroup from './components/BasicFormGroup.vue'
9+
import { type BasicInputDefaultProps } from './defaultProps'
10+
11+
const props = withDefaults(
12+
defineProps<
13+
BasicInputDefaultProps<string> & {
14+
inputClass?: string
15+
disableValidation?: boolean
16+
}
17+
>(),
18+
{
19+
type: 'number',
20+
autocapitalize: 'off',
21+
inputClass: '',
22+
disableValidation: false,
23+
}
24+
)
25+
26+
const emit = defineEmits<{
27+
(event: 'update:modelValue', eventArgs: string | undefined): void
28+
(event: 'focus'): void
29+
(event: 'blur'): void
30+
}>()
31+
const { model, errorMessage } = props.disableValidation
32+
? {
33+
model: useVModel(props, 'modelValue', emit),
34+
errorMessage: undefined,
35+
}
36+
: useValidationModel(props, emit)
37+
38+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
39+
let intl: any = null
40+
const phone = ref()
41+
onMounted(async () => {
42+
// await import('intl-tel-input/build/js/utils.js')
43+
intl = intlTelInput(phone.value, {
44+
separateDialCode: true,
45+
strictMode: true,
46+
initialCountry: 'de',
47+
autoPlaceholder: 'off',
48+
})
49+
})
50+
51+
onUnmounted(() => {
52+
intl?.destroy()
53+
})
54+
</script>
55+
56+
<template>
57+
<BasicFormGroup
58+
:id="id"
59+
:name="name"
60+
:label="label"
61+
:required="required"
62+
:error-message="errorMessage"
63+
>
64+
<div class="intl-tel-wrapper">
65+
<input
66+
:id="id || name || label"
67+
ref="phone"
68+
:value="model"
69+
type="tel"
70+
:placeholder="placeholder || label || name"
71+
:class="inputClass"
72+
:name="id || name || label"
73+
:disabled="disabled"
74+
/>
75+
</div>
76+
<template #label>
77+
<slot name="label"></slot>
78+
</template>
79+
</BasicFormGroup>
80+
</template>
81+
82+
<style lang="scss">
83+
@import 'intl-tel-input/build/css/intlTelInput.css';
84+
.intl-tel-wrapper {
85+
.iti {
86+
@apply block w-full;
87+
.form-control {
88+
@apply block w-full;
89+
}
90+
}
91+
}
92+
</style>

frontend/src/components/UIComponents/KontaktItem.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TrashIcon } from '@heroicons/vue/24/outline'
33
import { ref, watch } from 'vue'
44
55
import BasicCheckbox from '../BasicInputs/BasicCheckbox.vue'
6+
import BasicInputPhoneNumber from '../BasicInputs/BasicInputPhoneNumber.vue'
67
78
import BasicInput from '@/components/BasicInputs/BasicInput.vue'
89
import type { TKontaktSchema } from '@codeanker/api'
@@ -45,7 +46,7 @@ watch(
4546
placeholder="Nachname eingeben"
4647
required
4748
/>
48-
<BasicInput
49+
<BasicInputPhoneNumber
4950
v-model="kontakt.telefon"
5051
label="Mobiltelefonnummer"
5152
placeholder="Mobiltelefonnummer eingeben"

frontend/src/components/forms/person/FormContactGeneral.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { computed } from 'vue'
33
44
import BasicInput from '@/components/BasicInputs/BasicInput.vue'
5+
import BasicInputPhoneNumber from '@/components/BasicInputs/BasicInputPhoneNumber.vue'
56
67
export interface IContact {
78
email: string
@@ -37,9 +38,8 @@ const model = computed({
3738
placeholder="Email-Adresse"
3839
required
3940
/>
40-
<BasicInput
41+
<BasicInputPhoneNumber
4142
v-model="model.telefon"
42-
type="tel"
4343
label="Telefonnummer"
4444
placeholder="Telefonnummer"
4545
required

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)