kartik-v/dependent-dropdown
Composer 安装命令:
composer require kartik-v/dependent-dropdown
包简介
A multi level dependent dropdown JQuery plugin that allows nested dependencies.
README 文档
README
dependent-dropdown
A multi level dependent dropdown JQuery plugin that allows nested dependencies. The plugin allows you to convert normal select inputs, whose options are derived based on value selected in another input/or a group of inputs. It works both with normal select options and select with optgroups as well.
NOTE: Refer the CHANGE LOG for details on updates to various releases.
Features
- Apply the plugin on a select element and set dependency to one or more other input / select elements (including dependency nesting).
- Automatically convert
selectinputs with classdepdropto dependent dropdowns. The plugin supports HTML5 data attributes to configure the dependent dropdown options. - Automatically initialize dependent dropdowns based on preselected values (useful for update scenario).
- Supports both
selectinput with basicoptionsand select withoptgroups. - Automatically lock/disable the dependent dropdown until dependent results are available.
- The plugin uses ajax call to the server to render the list of dependent options.
- Allows a loading indicator to be displayed in dependent select until the results are fetched from the server.
- Configure your own loading progress text to be displayed for each dependent dropdown before the results are fetched from the server.
- Display a placeholder label with an empty value. For
optgroupsautomatically disable this option. - Triggers JQuery events for advanced development. Events currently available are
depdrop:init,depdrop:change,depdrop:beforeChange,depdrop:afterChange, anddepdrop:error. - Ability to configure HTML attributes of each
optionelement via ajax response (for example dynamically disabling some dropdown options or adding styles).
Documentation and Demo
View the plugin documentation and plugin demos at Krajee JQuery plugins.
Pre-requisites
-
Latest JQuery
-
All select inputs in markup must have a defined
IDattribute for the plugin to work. -
Tested to work currently with default HTML select input. It is not tested to work with other JQuery plugins that enhance the HTML select input (e.g. Select2, multiselect etc.). However, the plugin exposes events, which can be used in such situations.
-
The dependent dropdown is generated using an ajax call and hence requires a web server and web programming language to generate this. The plugin passes the dependent id values as an input to the ajax call via POST action. The ajax response should be a JSON encoded specified format like below:
{output: <dependent-list>, selected: <default-selected-value>}
where,
outputis an array of data for the dependent list of the format
{id: <option-value>, name: <option-name>}
selectedis the default selected value after the dependent dropdown is generated.
If you desire a dependent list containing optgroups then the output must be of the format
{group-name: {id: <option-value>, name: <option-name>}}
Installation
Using Bower
You can use the bower package manager to install. Run:
bower install dependent-dropdown
Using NPM
To install using the npm package manager run:
npm install dependent-dropdown
Using Composer
You can use the composer package manager to install. Either run:
$ php composer.phar require kartik-v/dependent-dropdown "@dev"
or add:
"kartik-v/dependent-dropdown": "@dev"
to your composer.json file
Manual Install
You can also manually install the plugin easily to your project. Just download the source ZIP or TAR ball and extract the plugin assets (css and js folders) into your project.
Usage
Step 1: Load the following assets in your header.
<link href="path/to/css/dependent-dropdown.min.css" media="all" rel="stylesheet" type="text/css" /> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script src="path/to/js/dependent-dropdown.min.js" type="text/javascript"></script> <!-- optionally if you need translation for your language then include locale file as mentioned below --> <script src="path/to/js/locales/<lang>.js"></script>
If you noticed, you need to load the jquery.min.js in addition to the dependent-dropdown.min.css and dependent-dropdown.min.js for the plugin to work with default settings. The locale file js/locales/<lang>.js can be optionally included for translating for your language if needed.
Step 2: Setup your select input markup to. Automatically set dependent dropdowns by adding the class depdrop and setting data attributes.
NOTE: All select inputs must have a defined ID attribute for the plugin to work.
<select id="parent-1"> <!-- your select options --> </select> <select id="child-1" class="depdrop" data-depends="['parent-1']" data-url="/path/to/child_1_list"> <!-- your select options --> </select> <select id="child-2" class="depdrop" data-depends="['parent-1', 'child-1']" data-url="/path/to/child_2_list"> <!-- your select options --> </select>
Due to array data being used for the data-depends attribute, you may need to escape the data like so:
<select id="child-1" class="depdrop" data-depends="["parent-1"]" data-url="/path/to/child_1_list"> <!-- your select options --> </select>
Step 2 (Alternative): You can initialize the plugin via javascript for your dependent dropdowns. For example,
$("#child-1").depdrop({ depends: ['parent-1'], url: '/path/to/child_1_list' }); $("#child-2").depdrop({ depends: ['parent-1', 'child-1'], url: '/path/to/child_2_list' });
Contributors
Code Contributors
This project exists thanks to all the people who contribute. [Contribute].
Financial Contributors
Become a financial contributor and help us sustain our community. [Contribute]
Individuals
Organizations
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]
License
dependent-dropdown is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.
kartik-v/dependent-dropdown 适用场景与选型建议
kartik-v/dependent-dropdown 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 5.21M 次下载、GitHub Stars 达 182, 最近一次更新时间为 2014 年 05 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「jquery」 「option」 「select」 「dropdown」 「dependent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kartik-v/dependent-dropdown 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kartik-v/dependent-dropdown 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kartik-v/dependent-dropdown 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Console Configuration Helper implementation.
CakePHP behavior plugin for easily generating some complicated queries like (bulk) insert/upsert etc.
PHP PDO Mysql select statement iterator implemented as multiple queries using LIMIT clauses
PHP library that allows linking queries from diferent physical databases using mysql pdo database connections
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Country select field type.
统计信息
- 总下载量: 5.21M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 186
- 点击次数: 35
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-05-01