1.0.13 • Published 1 year ago

vue-country-dropdown-2 v1.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Vue Country Dropdown 2

Country dropdown for Vue@2.

Demo

Installation

  • yarn:
      yarn add vue-country-dropdown-2
  • npm:
      npm i --save vue-country-dropdown-2

Usage

  • Install as a global component:

    import Vue from "vue";
    import VueCountryDropdown from "vue-country-dropdown-2";
    
    Vue.use(VueCountryDropdown);
  • Or use in a specific component

    import VueCountryDropdown from 'vue-country-dropdown-2'
    
    export default {
      components: {
        VueCountryDropdown
      }
    }
  • In your component:

    <template>
    ...
      <vue-country-dropdown
        @onSelect="onSelect"
        :preferredCountries="['TR', 'US', 'GB']"
        :defaultCountry="'TR'"
        :immediateCallSelectEvent="true"
        :enabledFlags="true"
        :enabledName="true"
        :enabledPhonecode="true"
        :showNotSelectedOption="true"
        :notSelectedOptionText="'Not Selected'"
        :disabled="false"
        :clearable="false"
        :multiple="false"
        :searchable="true"
        :closeOnSelect="true"
        :placeholder="'Select a country'"
      />
    ...
    <template>
    <script>
    export default {
      methods: {
         onSelect(country) {
           console.log(country);
           // Check the country object example below.
         },
      },
    }
    </script>

Country Object Example

{
    "id": 225,
    "name": "Turkey",
    "iso3": "TUR",
    "iso2": "TR",
    "numeric_code": "792",
    "phone_code": "+90",
    "capital": "Ankara",
    "currency": "TRY",
    "currency_name": "Turkish lira",
    "currency_symbol": "₺",
    "tld": ".tr",
    "native": "Türkiye",
    "region": "Asia",
    "subregion": "Western Asia",
    "timezones": [
        {
            "zoneName": "Europe/Istanbul",
            "gmtOffset": 10800,
            "gmtOffsetName": "UTC+03:00",
            "abbreviation": "EET",
            "tzName": "Eastern European Time"
        }
    ],
    "translations": {
        "kr": "터키",
        "br": "Turquia",
        "pt": "Turquia",
        "nl": "Turkije",
        "hr": "Turska",
        "fa": "ترکیه",
        "de": "Türkei",
        "es": "Turquía",
        "fr": "Turquie",
        "ja": "トルコ",
        "it": "Turchia",
        "cn": "土耳其",
        "tr": "Türkiye"
    },
    "latitude": "39.00000000",
    "longitude": "35.00000000",
    "emoji": "🇹🇷",
    "emojiU": "U+1F1F9 U+1F1F7"
}

Props

Property valueTypeDefault valueDescription
disabledBooleanfalseDisables the dropdown
defaultCountrystring''Set a country as selected at startup with iso code. ie 'TR'
defaultCountryByNamestring''Set a country as selected at startup with name. ie 'Turkey'
defaultCountryByPhoneCodestring''Set a country as selected at startup with phone code. ie '+90'
enabledNameBooleantrueEnable country name in the input
enabledFlagsBooleantrueEnable flags in the input
enabledPhonecodeBooleantrueEnable phone code in the input
clearableBooleanfalseUser can clear or not the selected country
multipleBooleanfalseSelect multiple country
searchableBooleantrueSet countries searchable
closeOnSelectBooleantrueClose country list on select
placeholderString''Set a placeholder for the input
preferredCountriesArray[]Preferred countries list, will be on top of the dropdown. ie ['TR', 'US', 'AL']
onlyCountriesArray[]List of countries will be shown on the dropdown. ie ['TR', 'US', 'AL']
ignoredCountriesArray[]List of countries will NOT be shown on the dropdown. ie ['TR', 'US', 'AL']
immediateCallSelectEventBooleanfalseCall the onSelect event when the component is mounted.
showNotSelectedOptionBooleanfalseThe Not Selected option is added to the top of the list. (All values are empty.)
notSelectedOptionTextStringNot SelectedReplace Not Selected text with another string.
countryNameTranslationString''Shows the name in the translation object instead of the country default name. ie 'tr'

Events

Property valueArgumentsDescription
onSelectObjectFires when the input changes with the argument is the object includes country object. (Check the country object example above)
opennoneTriggered when the dropdown is open.
closenoneTriggered when the dropdown is closed.
option_selectingObjectTriggered after an option has been selected, before updating internal state. (Return same object with onSelect).
option_selectedObjectTriggered when an option has been selected, after updating internal state. (Return same object with onSelect).
option_deselectingObjectTriggered when an option has been deselected, before updating internal state. (Return same object with onSelect).
option_deselectedObjectTriggered when an option has been deselected, after updating internal state. (Return same object with onSelect).

Highlights & Credits