• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Vue.js component implementing the select control with the jQuery select2 plugin.

vue-select

Build Status Coverage Status bitHound Score Dependency Status devDependency Status

A Vue.js component implementing the select control with the jQuery select2 plugin.

Demo

The demo page is HERE.

Screenshot

Requirements

Instllation

npm

$ npm install vue-select2

bower

$ bower install vue-select

Usage

The HTML snippets are as follows:

<div id="app">
  <div class="form-horizontal">
    <div class="form-group">
      <label for="select1" class="col-sm-3 control-label">
        A simple select:
      </label>
      <div class="col-sm-5">
        <vue-select class="vue-select1" name="select1" :options="options1" :model.sync="result1">
        </vue-select>
      </div>
      <div class="col-sm-4">
        <p class="form-control-static">
          Selected Result: <span class="vue-result1">{{result1}}</span>
        </p>
      </div>
    </div>
    <div class="form-group">
      <label for="select2" class="col-sm-3 control-label">
        A searchable select with names and localized in en-US:
      </label>
      <div class="col-sm-5">
        <vue-select class="vue-select2" name="select2"
                :options="options2" :model.sync="result2"
                :searchable="true" language="en-US">
        </vue-select>
      </div>
      <div class="col-sm-4">
        <p class="form-control-static">
          Selected Result: <span class="vue-result2">{{result2}}</span>
        </p>
      </div>
    </div>
    <div class="form-group">
      <label for="select3" class="col-sm-3 control-label">
        A searchable select with groups and localized in zh-CN:
      </label>
      <div class="col-sm-5">
        <vue-select class="vue-select3" name="select3"
                    :options="options3" :model.sync="result3"
                    :searchable="true" language="zh-CN">
        </vue-select>
      </div>
      <div class="col-sm-4">
        <p class="form-control-static">
          Selected Result: <span class="vue-result3">{{result3}}</span>
        </p>
      </div>
    </div>
  </div>
</div>

The Javascript snippets are as follows:

var vm = new Vue({
  el: "#app",
  components: {
    "vue-select": require("vue-select")
  },
  data: {
    options1: [
      "value1",
      "value2",
      "value3"
    ],
    options2: [{
      text: "name1",
      value: "value1"
    }, {
      text: "name2",
      value: "value2"
    }, {
      text: "name3",
      value: "value3"
    }],
    options3: [{
      label: "group1",
      options: [{
        text: "name1",
        value: "value1"
      }, {
        text: "name2",
        value: "value2"
      }, {
        text: "name3",
        value: "value3"
      }]
    }, {
      label: "group2",
      options: [{
        text: "name4",
        value: "value4"
      }, {
        text: "name5",
        value: "value5"
      }, {
        text: "name6",
        value: "value6"
      }]
    }],
    result1: "",
    result2: "",
    result3: ""
  }
});

Component Properties

options

The array of options of the selection control. It could be

  • an array of strings, e.g., ['opt1', 'opt2']; or
  • an array of objects specifying the text and value of each option, e.g., [{text: 'name1', value: 'val1'}, {text: 'name2', value: 'val2'}]; or
  • an array of objects specifying the option group, e.g.
    [{
      label: 'group1',
      options: [{text: 'name1', value: 'val1'}, {text: 'name2', value: 'val2'}]
    }, {
      label: 'group2',
      options: [{text: 'name3', value: 'val3'}, {text: 'name4', value: 'val4'}]
    }]
    

model

The model bind to the control, which must be a two way binding variable.

Note that the value of model could be set to null, and in that case the selection will be set to nothing. Also, if the selection is set to nothing (that is, the user delete the text in the input box of the selector), the value of the model will be set to null instead of an empty string.

searchable

The optional flag indicates whether to show the search box. The default value is false.

multiple

The optional flag indicates whether to use a multiple select control. The default value is false.

language

The optional code of language used by the select2 plugin.

The supported languages are exactly the same as the supported languages of the select2 plugin. In order to use the supported language, you must also include the corresponding "i18n" js file of the select2 plugin in your HTML file.

Note that the language code passed to this property could be a locale code consists of a language code and a country code, e.g., "en-US". The component will automatically convert the locale code to the language code supported by the select2 plugin. Since some languages have different variants in different country or region, e.g., "zh-CN" for the simplified Chinese and "zh-TW" for the traditional Chinese, it's recommended to use the locale code in the form of "[language]-[country]".

If this property is not set, and the vue-i18n plugin is used, the component will use the language code $language provided by the vue-i18n plugin; otherwise, the component will use the default value "en-US".

theme

The optional name of the theme of the select2 plugin. Default value is 'bootstrap'.

Note that in order to use the bootstrap theme, you must include the CSS file from the select2-bootstrap-theme project. And it's very important that the above CSS file must be included AFTER the CSS file of the bootstrap.

The following is the correct order for including CSS files:

<link rel="stylesheet" type="text/css" href="http://cdn.bootcss.com/select2/4.0.0/css/select2.css">
<link rel="stylesheet" type="text/css" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="https://select2.github.io/select2-bootstrap-theme/css/select2-bootstrap.css">

Check the demo page for details.

name

The optional name of the selection control.

API

control

This property is a reference to the JQuery selection of the base select control. It could be used to call the APIs of select2 plugin. For example, select.control.val(val) will set the value of the select to the specified value, where select is the reference to the vue-select component.

Contributing

  • Fork it !
  • Create your top branch from dev: git branch my-new-topic origin/dev
  • Commit your changes: git commit -am 'Add some topic'
  • Push to the branch: git push origin my-new-topic
  • Submit a pull request to dev branch of Haixing-Hu/vue-select repository !

Building and Testing

First you should install all depended NPM packages. The NPM packages are used for building and testing this package.

$ npm install

Then install all depended bower packages. The bower packages are depended by this packages.

$ bower install

Now you can build the project.

$ gulp build

The following command will test the project.

$ gulp test

The following command will perform the test and generate a coverage report.

$ gulp test:coverage

The following command will perform the test, generate a coverage report, and upload the coverage report to coveralls.io.

$ gulp test:coveralls

You can also run bower install and gulp build together with the following command:

npm run build

Or run bower install and gulp test:coveralls together with the following command:

npm run test

License

The MIT License

More Repositories

1

typesetting-standard

中文排版所需遵循的标准和规范
626
star
2

nju-thesis

南京大学学位论文XeLaTeX模板
TeX
406
star
3

vue-html-editor

A Vue.js component implementing the HTML editor with the jQuery summernote plugin.
JavaScript
389
star
4

vue-datetime-picker

A Vue.js component implementing the datetime picker control using the Eonasdan's bootstrap datetime picker plugin.
JavaScript
343
star
5

GBT7714-2005-BibTeX-Style

A GB/T 7714-2005 national standard compliant BibTeX style.
TeX
326
star
6

latex-chinese-fonts

Simplified Chinese fonts for the LaTeX typesetting.
180
star
7

vue-i18n

Internationalization plugin of Vue.js
JavaScript
62
star
8

vue-country-select

A Vue.js component implementing the select control used to select countries.
JavaScript
49
star
9

gift-to-lover

A personal gift to my lover.
JavaScript
33
star
10

xelatex-zh-book

An XeLaTeX document style for typesetting Simplified Chinese books.
TeX
24
star
11

vue-format

A Vue.js plugin for formatting messages.
JavaScript
19
star
12

bootstrap3-ie10-viewport-bug-workaround

The official workaround of the viewport bug of IE 10.0 for the bootstrap 3.
JavaScript
16
star
13

javafx-widgets

The useful widgets for JavaFX
Java
14
star
14

swt-widgets

Collect some useful SWT widgets for my applications.
Java
12
star
15

vue-titlecase

A Vue.js filter used to make a string titlecased.
JavaScript
12
star
16

nju-report

南京大学科技报告XeLaTeX模板
Shell
8
star
17

HanZi-Learning-ANKI-Cards

供儿童学习认识汉字的ANKI卡片模板及其生成器
Python
6
star
18

datatables-i18n

The i18n files of the datatables, renamed with the standard language identifiers, and registered in the bower.
5
star
19

animated-header.js

A fixed header that will animate its size on scroll.
HTML
3
star
20

vue3-class-component

The new vue-class-component for Vue3.
JavaScript
3
star
21

dqwl

Simulation of Discrete Quantum Walk on a Line using the Matlab.
MATLAB
3
star
22

beamer-chinese-translation

Translation of the LaTeX beamer package into Simplified/Traditional Chinese
Shell
3
star
23

qwViz

Visualisation of quantum walks on graphs
C
2
star
24

quantum-walk

The matlab simulator of quantum walks
MATLAB
2
star
25

commons

The common utilities used in Java programming.
Java
2
star
26

Haixing-Hu.github.io

The homepage of Haixing Hu.
Ruby
2
star
27

criteria

A collection of classes used to representing filtering/searching criteria.
Java
2
star
28

iLibrary

A multi-platform personal digit library software.
Java
1
star