GithubHelp home page GithubHelp logo

jquery-dependentselect's Introduction

jquery.dependentSelect plugin

jquery.dependentSelect plugin transforms your difficult select element with huge amount of options into widget with cascade select boxes. It might be city or student select, for example.

Features

  • Use local data, URL or function as data source
  • Access all defined widget options on server side
  • Use multiple and single widget without restrictions

Todo

  • Calculate all selects states in single widget with selected value

Use

You don’t need to change your HTML. Widget should work with your markup without changes. If the number of options is really huge you can load only selected.

Single widget with local data

Local data format is strict and currently can’t be changed.

    $(document).ready(function() {
      $('select#single-local-data').dependentSelect({
        isMultiple: false,
        selects: [
          { model: "Continent" },
          { model: "Country" },
          { model: "City" }
        ],
        dataSource: 
        {
             'Continent': {
                 values: [
                     { value: 1, text: "Asia" },
                     { value: 2, text: "Europe" }
                 ],
                 relatedTo: 'Country',
                 relations: {
                     1: [1,2,3],
                     2: [4,5]
                 }
             },
             'Country': {
                 values: [
                     { value: 1, text: 'Japan'  },
                     { value: 2, text: 'China'  },
                     { value: 3, text: 'Spain'  },
                     { value: 4, text: 'India' },
                     { value: 5, text: 'Czech Republic' },
                 ],
                 relatedTo: 'City',
                 relations: {
                     1: [1],
                     2: [2],
                     3: [3,4],
                     4: [5],
                     5: [6]
                 }
             },
             'City': {
                 values: [
                     { value: 1, text: 'Tokio' },
                     { value: 2, text: "Pekin" },
                     { value: 3, text: "Madrid" },
                     { value: 4, text: "Barcelona" },
                     { value: 5, text: "New Delhi" },
                     { value: 6, text: "Prague" },
                 ]
             }
         }
    });

Multiple widget with remote data

All options you set in ‘selects’ array will be accessible on server.

    $('select#single').dependentSelect({
      isMultiple: false,
      addEmpty: false,
      selects: [
        { model: "School", init: "findAll", key: "relatedGroups", targetModel: "Group" },
        { model: "Group", key: "relatedStudents", targetModel: "Student" },
        { model: "Student" }
      ],
      dataSource: 'index.php?module=get_data'
    });

Single widget with remote data and custom empty options

    $('select#single-add-empty').dependentSelect({
      isMultiple: false,
      addEmpty: '—',
      seklects: [
        { model: "School", init: "findAll", key: "relatedGroups", targetModel: "Group", emptyOptionCaption: "Select school..." },
        { model: "Group", key: "relatedStudents", targetModel: "Student", emptyOptionCaption: "Select group..." },
        { model: "Student", emptyOptionCaption: "Select student..." }
      ],
      dataSource: 'index.php?module=get_data'
    });

jquery-dependentselect's People

Contributors

temochka avatar

Watchers

 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.