Giter Club home page Giter Club logo

jquery-dependent-selects's Introduction

jQuery Dependent Selects

Overview

A jQuery plugin to allow multi-level select boxes that degrade gracefully. It only changes the markup (and very slightly at that) so the styling is all down to you.

Demo

You can check out some demos over here!

Usage

Ensure you have jQuery included in your page and include the jquery-dependent-selects.js script by adding something like this to your page's <head>:

Note: Change the src value to match the location of the scripts.

<script src="path/to/jquery.js"></script>
<script src="path/to/jquery.dependent-selects.js"></script>

Mark up your selects as you'd like them to work without JavaScript, ensuring their text displays a consistent separator. For example:

<select name="location" class="dependent">
  <option></option>
  <option value="238">London > North > Enfield</option>
  <option value="239">London > North > Barnet</option>
  <option value="240">London > South > Croydon</option>
  <option value="241">London > South > Bromley</option>
  <option value="242">London > South > Sutton</option>
  <option value="243">Bristol > St Pauls</option>
  <option value="244">Bristol > Horfield</option>
  <option value="245">Bristol > Bedminster</option>
  <option value="246">Bournemouth</option>
</select>

Initiate the plugin on the selects you would like it to be activated:

Note: It's best for this be done after the DOM is ready. For more info see this brief tutorial.

$('.dependent').dependentSelects();

Viola! Your select boxes should now be dependently nested.

Customisation

There's some options you can pass into jQuery Dependent Selects when called. They are listed here showing the defaults:

$('.example-class').dependentSelects({
  separator: ' > ', // String: The separator used to define the nesting in the option field's text
  placeholderOption: '', // String or array of strings: The text used for the sub select boxes' placeholder option.
                   // If an array, the first 'sub' level will be the first array item, you should manually create
                   // the top level's placeholder in the HTML.
  placeholderSelect: false, // Array of strings: The text used for placeholder select boxes for sub levels.
  class: false, // String: Add an extra class to all sub selects
  labels: false // Array of strings: The text used for the sub select boxes' labels. Label element is
                // inserted before sub select.
});

Contributing

The plugin is written in CoffeeScript and a Cakefile is included with build and watch tasks. If you'd like to contribute, please write CoffeeScript and use the Cake tasks to compile it.

  1. Fork project
  2. Checkout to a new branch (named after the feature / change you're making)
  3. Write code (as mentioned above)
  4. Submit pull request

License

Licenced under MIT. Copyright 2012 Mark J Smith, Simpleweb.

jquery-dependent-selects's People

Contributors

markjs avatar acaron avatar

Watchers

James Cloos avatar Novikov Bogdan avatar  avatar

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.