Skip to content

Docs for v2.x.x

Usage

  • Import default CSS to your project:

    js
    import 'vue-tel-input/dist/vue-tel-input.css';
  • In your component:

    html
    <template>
    ...
       <vue-tel-input v-model="phone"></vue-tel-input>
    ...
    <template>
    <script>
    import VueTelInput from 'vue-tel-input';
    
    export default {
      components: {
        VueTelInput,
      },
      data() {
        return {
          phone: '',
        };
      },
    }
    </script>

Use as a custom field of vue-form-generator

  • Add a component using vue-form-generator's abstractField mixin

    js
    // tel-input.vue
    <template>
      <vue-tel-input v-model="value"></vue-tel-input>
    </template>
    
    <script>
    import VueTelInput from 'vue-tel-input'
    import { abstractField } from 'vue-form-generator';
    
    export default {
      name: 'TelephoneInput',
      mixins: [abstractField],
      components: {
        VueTelInput,
      },
    };
    </script>
  • Register the new field as a global component

    js
      import Vue from 'vue';
      import TelInput from '<path>/tel-input.vue';
    
      import 'vue-tel-input/dist/vue-tel-input.css';
    
      Vue.component('field-tel-input', TelInput);
  • Now it can be used as tel-input in schema of vue-form-generator

    js
    var schema: {
      fields: [{
          type: "tel-input",
          label: "Awesome (tel input)",
          model: "telephone"
      }]
    };

Read more on vue-form-generator's instruction page

Props

PropertyTypeDefault valueDescription
defaultCountryString''Default country, will override the country fetched from IP address of user
disabledFetchingCountryBooleanfalseDisable fetching current country based on IP address of user
disabledBooleanfalseDisable input field
disabledFormattingBooleanfalseDisable formatting the phone number in the input, the formatted result still be accessible by formattedNumber returned from onInput event
placeholderStringEnter a phone numberPlaceholder for the input
requiredBooleanfalseRequired property for HTML5 required attribute
enabledCountryCodeBooleanfalseEnable country code in the input
enabledFlagsBooleantrueEnable flags in the input
preferredCountriesArray[]Preferred countries list, will be on top of the dropdown. ie ['AU', 'BR']
onlyCountriesArray[]List of countries will be shown on the dropdown. ie ['AU', 'BR']
ignoredCountriesArray[]List of countries will NOT be shown on the dropdown. ie ['AU', 'BR']
autocompleteString'on'Native input 'autocomplete' attribute
nameString'telephone'Native input 'name' attribute
maxLenNumber25Native input 'maxlength' attribute
wrapperClassesString | Array | Object''Custom classes for the wrapper
inputClassesString | Array | Object''Custom classes for the input
inputIdString''Custom 'id' for the input
dropdownOptionsObject{ disabledDialCode: false, tabindex: 0 }Options for dropdown, supporting disabledDialCode and tabindex
inputOptionsObject{ showDialCode: false, tabindex: 0 }Options for input, supporting showDialCode (always show dial code in the input) and tabindex
validCharactersOnlyBooleanfalseOnly allow valid characters in a phone number (will also verify in mounted, so phone number with invalid characters will be shown as an empty string)

Events

EventArgumentsDescriptionNotes
inputString, ObjectFires when the input changes with the argument is the object includes { number, isValid, country }onInput deprecated
validateObjectFires when the correctness of the phone number changes (from true to false or vice-versa) and when the component is mounted { number, isValid, country }onValidate deprecated
blurFires on blur eventonBlur deprecated
spaceFires on keyup.space eventonSpace deprecated
enterFires on keyup.enter eventonEnter deprecated
openFires when the flags dropdown opens
closeFires when the flags dropdown closes
country-changedObjectFires when country changed (even for the first time)Available from v2.4.2

Slots

SlotDescriptionNotes
arrow-iconReplace the arrow next to the flag with a component of your choiceAvailable from v2.4.3

Highlights & Credits

made with ❤ by Steven.