Created
August 8, 2013 19:52
-
-
Save jamstooks/6188077 to your computer and use it in GitHub Desktop.
Here's the spec for that jquery plugin I'm working on. There will also end up being a group of django widgets to go with it, like "CreditSelect" and "DocumentationFieldSelect" that can be restricted to specific CreditSets if necessary.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parent-child pull-downs | |
======================= | |
I need a way to generate a set of pulldowns that can populated based on what's selected in the parent. | |
Required Functionality | |
---------------------- | |
- can be initially populated with the existing value | |
- assumes unique id's at every level (not going to cater to that kinda craziness) | |
- can handle asynchronous requests to populate | |
Examples | |
-------- | |
**#1: An initially empty submission** | |
<select | |
data-populate="populateParent()" | |
data-child="child" | |
data-child-populate="populateChild()" | |
name="parent" | |
id="parent"> | |
</select> | |
<script> | |
function populateParent() { | |
return [ | |
['p1', '1'], | |
['p2', '2'] | |
] | |
} | |
function populateChild() { | |
return [ | |
['c1', '1'], | |
['c2', '2'] | |
] | |
} | |
$("#parent").ParentChildSelect(); | |
</script> | |
The #parent select is populated and when an option is selected a child select is created. | |
**#2: Populating with an initial id** | |
Same as above, except: | |
$("#parent").ParentChildSelect(['1', '1']) | |
This will populate the parent dropdown, select 'p1' and then populate the second dropdown and select 'c1'. | |
**#3: Populate using ajax requests** | |
The callback identified by `data-populate` makes this system pretty versatile, but population will require some queueing during the initialization process. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment