1.0.7 • Published 1 year ago

vue-state-dropdown v1.0.7

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

Vue State Dropdown

State dropdown for Vue@2.

Demo

Installation

  • yarn:
      yarn add vue-state-dropdown
  • npm:
      npm i --save vue-state-dropdown

Usage

  • Install as a global component:

    import Vue from "vue";
    import VueStateDropdown from "vue-state-dropdown";
    
    Vue.use(VueStateDropdown);
  • Or use in a specific component

    import VueStateDropdown from 'vue-state-dropdown'
    
    export default {
      components: {
        VueStateDropdown
      }
    }
  • In your component:

    <template>
    ...
      <vue-state-dropdown
        @onSelect="onSelect"
        :countryCode="'tr'"
        :selectFirstItem="true"
        :preferredStates="['06', '34']"
        :immediateCallSelectEvent="true"
        :disabled="false"
        :clearable="false"
        :multiple="false"
        :searchable="true"
        :closeOnSelect="true"
      />
    ...
    <template>
    <script>
    export default {
      methods: {
         onSelect(state) {
           console.log(state);
           // Check the state object example below.
         },
      },
    }
    </script>

State Object Example

{
  "id": 2217,
  "name": "Ankara",
  "country_id": 225,
  "country_code": "TR",
  "country_name": "Turkey",
  "state_code": "06",
  "type": "province",
  "latitude": "39.78052450",
  "longitude": "32.71813750"
}

Props

Property valueTypeDefault valueDescription
disabledBooleanfalseDisables the dropdown
countryCodestring''Get states by country code. ie 'tr'
countryNamestring''Get states by country name. ie 'turkey'
countryIdNumbernullGet states by country id. ie 225
defaultStateNumber''Set a state as selected at startup with state id. ie 2217
defaultStateByNamestring''Set a state as selected at startup with state name. ie 'Ankara'
selectFirstItemBooleanfalseSet first state in the list as selected
clearableBooleanfalseUser can clear or not the selected country
multipleBooleanfalseSelect multiple country
searchableBooleantrueSet states searchable
closeOnSelectBooleantrueClose country list on select
placeholderString''Set a placeholder for the input
preferredStateArray[]Preferred states list, will be on top of the dropdown. ie ['06', 'WTO']
onlyStatesArray[]List of states will be shown on the dropdown. ie ['06', 'WTO']
ignoredStatesArray[]List of states will NOT be shown on the dropdown. ie ['06', 'WTO']
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.

Events

Property valueArgumentsDescription
onSelectObjectFires when the input changes with the argument is the object includes state object. (Check the state 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