/easy-select

easy-select is a jQuery plugin for text input with select box (known also as drop down list) support

Primary LanguageJavaScript

Easy Select Plugin

http://www.webdeveasy.com/easy-select-plugin

Demo here

Getting Started

  1. Download the plugin from here.
  2. Add a reference to jquery.easy-select.js and easy-select.css in your page. You can use the minified version instead by using jquery.easy-select.min.js and easy-select.min.css.
  3. In order to use the plugin on text input element:
    Markup: <input type="text" class="my-input" />
    JavaScript: $('.my-input').easySelect();

Options

Easy select has a few options:

items

Type: Array of objects Default: `[]` Array of items for the select box.

idKey

Type: String Default: `id` The name of the attribute that represents the item id.

textKey

Type: String Default: `text` The name of the attribute that represents the item text.

onSelect

Type: Function Default: `null` A callback function that triggered every time a new item gets selected.

Methods

Easy select has also a few useful methods. In order to use them you need to access the API object:

$('.my-input').data('easySelect');

getValue()

In order to get the selectd text you can read the value of your text input. getValue() method returns the value (or id) of the selected item.

$('.my-input').data('easySelect').getValue();

setItems()

setItems() method lets you change the items list during runtime. This method is useful when you want to load data asynchronously.

$.get('url/to/data').done(function(items) {
    $('.my-input').data('easySelect').setItems(items);
});

destroy()

destroy() method destroys the plugin by removing unnecessary elements and unbinding events.

$('.my-input').data('easySelect').destroy();

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Make your changes on the src folder, never on the dist folder
  4. You can use grunt build and grunt preview commands in order to see your changes on the demo
  5. Commit your changes: git commit -m 'Add some feature'
  6. Push to the branch: git push origin my-new-feature
  7. Submit a pull request