Code Monkey home page Code Monkey logo

vue-tel-input's Introduction

vue-tel-input-logo

vue-tel-input

International Telephone Input with Vue.

npm stars

In-action GIF

Documentation and Demo

Visit the website

Vue 2 Support

vue-tel-input@legacy: Guide

Changelog

Go to Github Releases

Getting started

  • Install the plugin:

    npm install vue-tel-input
  • Add the plugin into your app:

    import Vue from 'vue';
    import VueTelInput from 'vue-tel-input';
    import 'vue-tel-input/vue-tel-input.css';
    
    const app = createApp(App);
    app.use(VueTelInput);
    app.mount('#app');

    More info on installation

  • Use the vue-tel-input component:

    <template>
      <vue-tel-input v-model="phone"></vue-tel-input>
    </template>

Installation

npm

  npm install vue-tel-input

Install the plugin into Vue:

import { createApp } from 'vue';
import App from './App.vue';
import VueTelInput from 'vue-tel-input';
import 'vue-tel-input/vue-tel-input.css';

const globalOptions = {
  mode: 'auto',
};

const app = createApp(App);
app.use(VueTelInput, globalOptions); // Define default global options here (optional)
app.mount('#app');

View all available options in Props.

Or use the component directly:

<template>
  <vue-tel-input v-model="phone" mode="international"></vue-tel-input>
</template>

<script>
  import { ref } from 'vue';
  import { VueTelInput } from 'vue-tel-input';
  import 'vue-tel-input/vue-tel-input.css';

  export default {
    components: {
      VueTelInput,
    },

    setup() {
      const phone = ref(null);

      return {
        value,
      };
    },
  };
</script>

Browser

<script src="https://unpkg.com/vue-tel-input"></script>
<link rel="stylesheet" href="https://unpkg.com/vue-tel-input/dist/vue-tel-input.css" />

If Vue is detected in the Page, the plugin is installed automatically.

** Otherwise, manually install the plugin into Vue:

app.use(window['vue-tel-input']);

Component lazy loading

Since the library is about 200kb of JavaScript and 100kb of CSS in order to improve initial page loading time you might consider importing it asynchronously only when user navigates to the page where the library is actually needed. The technique is called Lazy Load and you can use it in some modern bundlers like Webpack and Rollup.

<!-- your-component.vue-->
<template>
  <vue-tel-input v-model="value"></vue-tel-input>
</template>
<script>
  const VueTelInput = () =>
    Promise.all([
      import(/* webpackChunkName: "chunk-vue-tel-input" */ 'vue-tel-input'),
      import(/* webpackChunkName: "chunk-vue-tel-input" */ 'vue-tel-input/vue-tel-input.css'),
    ]).then(([{ VueTelInput }]) => VueTelInput);

  export default {
    components: {
      VueTelInput,
    },
  };
</script>

As you see, we don't use Vue SFC <style></style> tag here to import component's css as it would result in CSS going to the main/vendors bundle instead of being downloaded on demand.

Development

Clone the project

  git clone https://github.com/iamstevendao/vue-tel-input.git

Go to the project directory

  cd vue-tel-input

Install dependencies

  npm install

Start the server

  npm run dev

License

Copyright (c) 2018 Steven Dao. Released under the MIT License.

made with ❤ by Steven.

vue-tel-input's People

Contributors

abu-yusuf-dev avatar alexanderjet avatar bkarlson avatar chernavskikh avatar cuongle-hdwebsoft avatar daniil4udo avatar dmncodes avatar f1729 avatar fabiosal avatar flangofas avatar flo2315 avatar homersimpsons avatar iamstevendao avatar kalcifield avatar kazvaggos avatar lwolodkiewiczftdev avatar maedekaboli avatar mariusgen avatar merceyz avatar mozzi avatar punit-wingify avatar revelyusuf avatar serbemas avatar simllll avatar suits-at avatar tiagoroldao avatar tijascott avatar treighmawaka avatar waveo-wangxiao avatar yamensharaf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-tel-input's Issues

Way to hide "Country code" label

I would like only flag and prefix (+48) displayed in language chooser. I don't want "Country code" label displayed. How do I hide it?

Errors: Callback, timeout and preselected country not available

I'm doing everything as you did in the example, still it gives me errors.
i just wanted some country pre-selected

screen shot 2018-05-17 at 13 59 09

My code:

<script> import VueTelInput from 'vue-tel-input' export default { data() { return { phone:'' } }, components: { 'vue-tel-input': VueTelInput }, methods: { /** * @param {string} number * the phone number inputted by user, will be formatted along with country code * // Ex: inputted: (AU) 0432 432 432 * // number = '+61432421546' * * @param {Boolean} isValid * @param {string} country */ onInput({ number, isValid, country }) { console.log(number, isValid, country); }, } } </script> <style> .domainContactForm { width: 100%; } .dropdown-menu.show { max-height: 300px; overflow: scroll; } </style>

Return country object instead of country name

Hi,
firstly, thanks for this plugin, it looks like the best vue specific plugin for this purpose, especially after Bootstrap dependency was removed :)

Anyway would be good to get country object in the onInput callback instead of just country name. In my use case I need to also send country alpha2 code to the backend.

I found possible workaround by using ref on vue-tel-input element and then accessing activeCountry.

Change country code with disabledFormatting set to false

Would be cool if, when the disabledFormatting = false, when the user changes the country, the old country code is automatically replaced with the new one.

Example:

Step 1

Country: France (+33)
Formatted number: +33 3 33 33 33 33
isValid: true

Step 2

The user changes the country
Country: Switzerland (+41)
Formatted number: +41333333333
isValid: false

Step 3

The user changes the country
Country: Germany (+49)
Formatted number: +49 33333 333
isValid: true

bootstrap 4 styling break

after update to newest version 2.0.18

image

before

image

code for the field did not change

    <vue-tel-input 
    v-model="form.data.phone" 
    name="phone" 
    ref="phone" 
    id="phone" 
    v-validate="{ phoneNumber:true }"
    class="form-control" 
    :class="{'is-invalid':errors.has('phone')}"
    autocomplete="none" 
    placeholder="Mobile">
    </vue-tel-input>

Cant resolve fs & net.

ERROR in .//vue-tel-input/dist/vue-tel-input.common.js
Module not found: Error: Can't resolve 'fs' in 'C:\Users\ctaljaardt\Documents\GitHub\Caselight\user_interface\node_modules\vue-tel-input\dist'
@ ./
/vue-tel-input/dist/vue-tel-input.common.js 1:164316-164329
@ ./~/vue-tel-input/index.js
@ ./src/main.js
@ multi ./build/dev-client ./src/main.js

ERROR in .//vue-tel-input/dist/vue-tel-input.common.js
Module not found: Error: Can't resolve 'net' in 'C:\Users\ctaljaardt\Documents\GitHub\Caselight\user_interface\node_modules\vue-tel-input\dist'
@ ./
/vue-tel-input/dist/vue-tel-input.common.js 1:164486-164500
@ ./~/vue-tel-input/index.js
@ ./src/main.js
@ multi ./build/dev-client ./src/main.j

Very large images are loaded upon mount

Upon mounting a vue-tel-input component, ALL flag images are loaded, which adds up to 4.1 MB gzipped. This is way too much, even if we lazy load the images

image

It seems that the images in behdad/region-flags are large files and the dimensions are way bigger than the displayed size. There's an open issue to provide alternate sizes fonttools/region-flags#12 but doesn't really seem to have much activity or push behind it.

I would propose switching to a sprite solution, maybe like patw0929/react-intl-tel-input's [email protected](64.2kb) / sprite.scss

Is there any interest in an update to switch to a sprite? Any other ideas? I am interested in using this component but I cannot justify the 4.1 MB of images right now!

Country list selector appear behind certain components (z-index)

The country list selector appears behind specific components.
I'm using Vuetify on my project and components like button are in front of the country list selector.
image

I fork the repository and correct the problem by adding z-index: 1; on <ul> of the dropdown.

disabledFetchingCountry not working

is not working am still getting hit to this url https://ipinfo.io/json?callback=__jp0

<vue-tel-input v-model="phone" 
@onInput="onInput"
:disabledFetchingCountry="true"
:placeholder="'Enter Your Phone Number'"
 >
</vue-tel-input>

Warning when using Nuxt

Hi, I'm using Nuxt 2.0 and I had been using vue-tel-input since version 2.0.10 without any problem. But recently I updated it to version 2.0.18 and it started to throw the following warning:

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

As far as I know, it is an issue with webpack itself but is there something I can do?

Impossible to listen to events in Vue 2

The events 'onInput', 'onValidate' and 'onBlur' are camelCased and thus can't work in Vue 2 since listening to the kebab-cased version will have no effect and the v-on event listeners will be automatically transformed to lowercase (due to HTML’s case-insensitivity).

v-model works only one-way, when it's supposed to work two-way.

My vue-tel-input component looks like this: <vue-tel-input v-model="phone"></vue-tel-input>.
It changes phone in data of its parent component, but when i change phone in parent component vue-tel-input isn't changing its phone data value. Here's the picture of vue-tel-input state:
image
As you can see value is passed through v-model, but it's not set in the data of the component. It shoud be set, because v-model means two-way binding and not one-way, like it works now.
To reproduce it you can do it like that:
<vue-tel-input v-model="phone"></vue-tel-input> <input v-model="phone">
When you are typing something into vue-tel-input it will change what is displayed in simple input, but when you are typing into simple input nothing will change in vue-tel-input.

Placeholder option - number example based on defaultCountry

Hi. First off, thanks for creating this plugin :)

I just wanted to ask whether there are any plans to add (and expose, code-wise?) properly formatted phone number examples for different countries, so we could choose to use an example of a properly formatted telephone number as placeholder values (based on whichever country is selected)?
That way we could have eg +1 202 555 0146 as placeholder value in case US is chosen by user (or set as defaultCountry), or eg. +386 31 100 100 in case Slovenia us chosen by the user, ...

:preferredCountries don't work

 <vue-tel-input 
v-model="phone"
 :required="true"
:preferredCountries="['us','uk','fr','de','fi','au','mx','br','sw','es','is']">
</vue-tel-input>

result:
2019-02-06_14-07-48

Unkown Custom element

[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.

found in

--->

Am I missing a dependency?

country change event

Hi,

when entered the mobile number. After changing the country need to remove old values and country also need to change

Cannot give value to the component

<vue-tel-input @onInput="onInput" v-bind:phone="newContact.phoneNumber" name="phone number" v-validate="'required'" data-vv-delay="1000"></vue-tel-input>
I am trying to load data to the input field, but I cannot find how to do it.

feature : I18n all-countries.js

We would like to customize the list of countries to i18n it.
It will depend on the locale of the user and we need to be able to switch all the time.

List of countries

Suggestion. Add to package custom property as onlyCountries, which contains limited list of countries abbrevs

Pass the country from the value on creation

When you pass in a value for the input which has the country code prefix, the expected behaviour is that the component will initialise on the country with the prefix.

phone: '+93 34 234 3434'
 vue-tel-input(v-model="phone")

Instead it will set the country based on the users country. In my case, it will always show Australia regardless of the phone prefix.

The implementation of this is fairly straight forward, the country can be found using the below code and set programatically. For fixing this myself without forking this repo, i've passed the default country property as the parsed country code.

import { parsePhoneNumberFromString } from 'libphonenumber-js'
...
this.country = parsePhoneNumberFromString(this.phone).country
...
 vue-tel-input(v-model="phone" :default-country="this.country")

v2.0.5 should not be a minor

Our build broke today because of version 2.0.5

One of the changes in this version is the removal of a full directory. This is clearly not minor change as it's not backward compatible.

I'm not proposing to change the version now, but in the future it would be nice to consider backward compatibility and thus stick to semver.

Thanks in advance

Sprites.css references githubusercontent.com

Looking at sprites.css, I see the flag images are loaded from githubusercontent.com. This is a potential issue.

There should be a way for referencing these image files locally or at least provided a method to specify an alternative base path for these images.

Code in question:

.iti-flag {
  width: 20px;
  height: 15px;
  box-shadow: 0px 0px 1px 0px #888;
  background-image: url("https://raw.githubusercontent.com/EducationLink/vue-tel-input/master/src/assets/flags.png");
  background-repeat: no-repeat;
  background-color: #dbdbdb;
  background-position: 20px 0;
}
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) {
  .iti-flag {
    background-image: url("https://raw.githubusercontent.com/EducationLink/vue-tel-input/master/src/assets/[email protected]");
  }
}

Chrome autofill broken

Hi,

We're using this plugin in our VueJs app and noticed something was off.

Whenever you enter a number manually everything works as expected.
But when you use the autofill in chrome the hidden fields stay empty.
This means our users will see the fields being filled in but nothing is saved.

To combat this we wanted to use autocomplete='off' but this is not passed onto the hidden input fields.

Any ideas of what we might be able to do?

And thank you for all the work put into this plugin, much appreciated!

How to check response without editing phonenumber?

Hi!

If I use vue-tel-input and define a v-model that already contains a phone-number, I see that vue-tel-input internally checks and knows if it's valid or not, but how can I know this from the parent component?

I am looking for a way for vue-tel-input to emit the response back to its parent without directly editing the field (which would trigger onInput).

A typical usercase is submitting a form without doing changes to the (prefilled) telephone-number field and making sure vue-tel-input find the number valid.

Do you have an idea?

How to set country programmatically?

I use this in a checkout form with IP detection which works out fine most of the time.
However I also have a country field and I would like to change the tel country prefix according to the country field value.

Is it possible to override the country somehow?

There should be prop named "disabled"

Now if I want to disable input for phone number and dropdown for countries I must do it manually through the DOM methods, it's not good to do so. So I think there should be :disabled prop, so I can just pass one parameter and the component will add :disabled attribute to input and hide dropdown.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.