forked from dnasir/jquery-cascading-dropdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
377 lines (353 loc) · 9.14 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>jQuery Cascading Dropdown Plugin Examples</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Stylesheets here -->
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/css/bootstrap.min.css" />
<style type="text/css">
.bs-docs-example {
position: relative;
margin: 15px 0;
padding: 39px 19px 14px;
background-color: #fff;
border: 1px solid #ddd;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.bs-docs-example:after {
content: "Example";
position: absolute;
top: -1px;
left: -1px;
padding: 3px 7px;
font-size: 12px;
font-weight: bold;
background-color: #f5f5f5;
border: 1px solid #ddd;
color: #9da0a4;
-webkit-border-radius: 4px 0 4px 0;
-moz-border-radius: 4px 0 4px 0;
border-radius: 4px 0 4px 0;
}
</style>
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shCore.css">
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/styles/shThemeDefault.css">
</head>
<body>
<div class="container">
<div class="page-header">
<h1>jQuery Cascading Dropdown <small>Examples</small></h1>
</div>
<h4>Basic</h4>
<p>This is a basic dropdown setup where the second dropdown is dependent on the first dropdown having a value, and the third dropdown is dependent on either the first or second one having a value.</p>
<div id="example1" class="bs-docs-example">
<select class="step1">
<option value="">Please select an option</option>
<option>Option1</option>
<option>Option2</option>
<option>Option3</option>
<option>Option4</option>
</select>
<select class="step2">
<option value="">Please select an option</option>
<option>Option5</option>
<option>Option6</option>
<option>Option7</option>
<option>Option8</option>
</select>
<select class="step3">
<option value="">Please select an option</option>
<option>Option9</option>
<option>Option10</option>
<option>Option11</option>
<option>Option12</option>
</select>
</div>
<h6>Code</h6>
<div>
<pre class="brush: js">$('#example1').cascadingDropdown({
selectBoxes: [
{
selector: '.step1'
},
{
selector: '.step2',
requires: ['.step1']
},
{
selector: '.step3',
requires: ['.step1', '.step2']
}
]
});</pre>
</div>
<br>
<h4>Dynamic</h4>
<p>This example shows how you can create a completely dynamic group of dropdowns. Dropdowns with dependencies will react based on the rules given, and fetch its own list from the server via Ajax. </p>
<p>In this example you can also see how you the textKey and valueKey is used, and how you can override those values for each individual select box.</p>
<div id="example2" class="bs-docs-example">
<select class="step1">
<option value="">Please select an option</option>
</select>
<select class="step2">
<option value="">Please select an option</option>
</select>
<select class="step3">
<option value="">Please select an option</option>
</select>
</div>
<h6>Code</h6>
<div>
<pre class="brush: js">$('#example2').cascadingDropdown({
textKey: 'label',
valueKey: 'value',
selectBoxes: [
{
selector: '.step1',
paramName: 'cId',
url: '/api/country'
},
{
selector: '.step2',
requires: ['.step1'],
paramName: 'sId',
url: '/api/sector',
valueKey: 'sectorId'
},
{
selector: '.step3',
requires: ['.step1', '.step2'],
requireAll: true,
url: '/api/offices',
onChange: function(value){
alert(value);
}
}
]
});</pre>
</div>
<br>
<h4>Combined</h4>
<p>This example demonstrates the plugin's capability to combine both static and dynamic dropdowns.</p>
<div id="example3" class="bs-docs-example">
<select class="step1">
<option value="">Please select an option</option>
<option value="uk">United Kingdom</option>
<option value="my">Malaysia</option>
</select>
<select class="step2">
<option value="">Please select an option</option>
<option value="1">Automotive</option>
<option value="2">Oil & Gas</option>
<option value="3">IT</option>
</select>
<select class="step3">
<option value="">Please select an option</option>
</select>
</div>
<h6>Code</h6>
<div>
<pre class="brush: js">$('#example3').cascadingDropdown({
selectBoxes: [
{
selector: '.step1',
paramName: 'cId'
},
{
selector: '.step2',
paramName: 'sId'
},
{
selector: '.step3',
requires: ['.step1', '.step2'],
requireAll: true,
url: '/api/offices',
textKey: 'label',
valueKey: 'value',
onChange: function(value){
alert(value);
}
}
]
});</pre>
</div>
<br>
<p class="text-center"><small>Copyright © 2013 <a href="http://dnasir.com">Dzulqarnain Nasir</a></small></p>
</div>
<!-- Scripts here -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.5.1/jquery.mockjax.js"></script>
<script type="text/javascript" src="jquery.cascadingdropdown.js"></script>
<script type="text/javascript">
// Some mockjax code to simulate Ajax calls
$.mockjax({
url: '/api/country',
contentType: 'application/json; charset=utf-8',
responseText: JSON.stringify([
{
label: 'United Kingdom',
value: 'uk'
},
{
label: 'Malaysia',
value: 'my'
}
])
});
$.mockjax({
url: '/api/sector',
contentType: 'application/json; charset=utf-8',
responseText: JSON.stringify([
{
label: 'Automotive',
sectorId: '1'
},
{
label: 'Oil & Gas',
sectorId: '2'
},
{
label: 'IT',
sectorId: '3'
}
])
});
$.mockjax({
url: '/api/offices',
contentType: 'application/json; charset=utf-8',
response: function(settings){
var data = settings.data;
var response = [];
if(data.cId == 'uk'){
switch(data.sId){
case '1':
case '2':
response = [
{
label: 'London Office',
value: 'Link to London Office page'
},
{
label: 'Manchester Office',
value: 'Link to Manchester Office page'
}
];
break;
case '3':
response = [
{
label: 'Southampton Office',
value: 'Link to Southampton Office page'
}
];
break;
}
}
else if(data.cId == 'my'){
switch(data.sId){
case '1':
case '2':
response = [
{
label: 'Kuala Lumpur Office',
value: 'Link to Kuala Lumpur Office page'
},
{
label: 'Putrajaya Office',
value: 'Link to Putrajaya Office page'
}
];
break;
case '3':
response = [
{
label: 'Penang Office',
value: 'Link to Penang Office page'
}
];
break;
}
}
this.responseText = JSON.stringify(response);
}
});
$(document).ready(function(){
$('#example1').cascadingDropdown({
selectBoxes: [
{
selector: '.step1'
},
{
selector: '.step2',
requires: ['.step1']
},
{
selector: '.step3',
requires: ['.step1', '.step2']
}
]
});
$('#example2').cascadingDropdown({
textKey: 'label',
valueKey: 'value',
selectBoxes: [
{
selector: '.step1',
paramName: 'cId',
url: '/api/country'
},
{
selector: '.step2',
requires: ['.step1'],
paramName: 'sId',
url: '/api/sector',
valueKey: 'sectorId'
},
{
selector: '.step3',
requires: ['.step1', '.step2'],
requireAll: true,
url: '/api/offices',
onChange: function(value){
alert(value);
}
}
]
});
$('#example3').cascadingDropdown({
selectBoxes: [
{
selector: '.step1',
paramName: 'cId'
},
{
selector: '.step2',
paramName: 'sId'
},
{
selector: '.step3',
requires: ['.step1', '.step2'],
requireAll: true,
url: '/api/offices',
textKey: 'label',
valueKey: 'value',
onChange: function(value){
alert(value);
}
}
]
});
});
</script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shCore.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushJScript.js"></script>
<script type="text/javascript">
SyntaxHighlighter.all();
</script>
</body>
</html>