Phone.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!--
  2. Champs de saisie d'un numéro de téléphone
  3. @see https://github.com/paul-thebaud/v-phone-inpu
  4. -->
  5. <template>
  6. <v-phone-input
  7. :model-value.number="modelValue"
  8. :rules="rules"
  9. :variant="variant"
  10. :label="label || field ? $t(label ?? field) : undefined"
  11. defaultCountry="FR"
  12. @update:model-value="onUpdate($event)"
  13. :invalidMessage="(n) => $t('invalid_phone_number', { example: n.example})"
  14. />
  15. </template>
  16. <script setup lang="ts">
  17. type ValidationRule = (value: string | number | null) => boolean | string
  18. const props = defineProps({
  19. modelValue: {
  20. type: String,
  21. required: true,
  22. },
  23. /**
  24. * Nom de la propriété d'une entité lorsque l'input concerne cette propriété
  25. * - Utilisé par la validation
  26. * - Laisser null si le champ ne s'applique pas à une entité
  27. */
  28. field: {
  29. type: String,
  30. required: false,
  31. default: null,
  32. },
  33. /**
  34. * Label du champ
  35. * Si non défini, c'est le nom de propriété qui est utilisé
  36. */
  37. label: {
  38. type: String,
  39. required: false,
  40. default: null,
  41. },
  42. /**
  43. * Règles de validation
  44. * @see https://vuetify.cn/en/components/forms/#validation-with-submit-clear
  45. */
  46. rules: {
  47. type: Array as PropType<ValidationRule[]>,
  48. required: false,
  49. default: () => [],
  50. },
  51. /**
  52. * @see https://vuetifyjs.com/en/api/v-autocomplete/#props-variant
  53. */
  54. variant: {
  55. type: String as PropType<
  56. | 'filled'
  57. | 'outlined'
  58. | 'plain'
  59. | 'underlined'
  60. | 'solo'
  61. | 'solo-inverted'
  62. | 'solo-filled'
  63. | undefined
  64. >,
  65. required: false,
  66. default: 'outlined',
  67. },
  68. })
  69. const emit = defineEmits(['update:modelValue'])
  70. const onUpdate = (event: string|null) => {
  71. if(event === ''){
  72. event = null
  73. }
  74. emit('update:model-value', event)
  75. }
  76. </script>
  77. <style lang="scss">
  78. </style>