-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.html
More file actions
478 lines (475 loc) · 25.3 KB
/
Copy pathexample.html
File metadata and controls
478 lines (475 loc) · 25.3 KB
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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!--head-->
<title>Meta Input jQuery Widget | javascript autocomplete script for input and select tags</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<link href="css/meta_input.css" rel="stylesheet">
<style>
h2 {
font-size: 22px;
}
table.custom-suggest {
width: 100%;
}
.example {
padding: 8px 10px;
background: #d1ebc7;
}
.explain {
padding: 10px 10px 20px 10px;
}
.custom-suggest>tbody>tr>td:first-child {
width: 50px;
}
.custom-suggest img {
width: 45px;
height: 45px;
border: 2px solid white;
border-radius: 50%;
}
.custom-suggest small {
color: #888;
}
.custom-suggest b {
display: block;
padding: 2px;
width: 100%;
}
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="js/meta_input.js"></script>
<script>
var source = {"AF":"Afghanistan","AL":"Albania","DZ":"Algeria","AS":"American Samoa","AD":"Andorra","AO":"Angola","AI":"Anguilla","AQ":"Antarctica","AG":"Antigua and Barbuda","AR":"Argentina","AM":"Armenia","AW":"Aruba","AU":"Australia","AT":"Austria","AZ":"Azerbaijan","BS":"Bahamas","BH":"Bahrain","BD":"Bangladesh","BB":"Barbados","BY":"Belarus","BE":"Belgium","BZ":"Belize","BJ":"Benin","BM":"Bermuda","BT":"Bhutan","BO":"Bolivia","BA":"Bosnia and Herzegovina","BW":"Botswana","BV":"Bouvet Island","BR":"Brazil","BQ":"British Antarctic Territory","IO":"British Indian Ocean Territory","VG":"British Virgin Islands","BN":"Brunei","BG":"Bulgaria","BF":"Burkina Faso","BI":"Burundi","KH":"Cambodia","CM":"Cameroon","CA":"Canada","CT":"Canton and Enderbury Islands","CV":"Cape Verde","KY":"Cayman Islands","CF":"Central African Republic","TD":"Chad","CL":"Chile","CN":"China","CX":"Christmas Island","CC":"Cocos [Keeling] Islands","CO":"Colombia","KM":"Comoros","CG":"Congo - Brazzaville","CD":"Congo - Kinshasa","CK":"Cook Islands","CR":"Costa Rica","HR":"Croatia","CU":"Cuba","CY":"Cyprus","CZ":"Czech Republic","CI":"C\u00f4te d\u2019Ivoire","DK":"Denmark","DJ":"Djibouti","DM":"Dominica","DO":"Dominican Republic","NQ":"Dronning Maud Land","DD":"East Germany","EC":"Ecuador","EG":"Egypt","SV":"El Salvador","GQ":"Equatorial Guinea","ER":"Eritrea","EE":"Estonia","ET":"Ethiopia","FK":"Falkland Islands","FO":"Faroe Islands","FJ":"Fiji","FI":"Finland","FR":"France","GF":"French Guiana","PF":"French Polynesia","TF":"French Southern Territories","FQ":"French Southern and Antarctic Territories","GA":"Gabon","GM":"Gambia","GE":"Georgia","DE":"Germany","GH":"Ghana","GI":"Gibraltar","GR":"Greece","GL":"Greenland","GD":"Grenada","GP":"Guadeloupe","GU":"Guam","GT":"Guatemala","GG":"Guernsey","GN":"Guinea","GW":"Guinea-Bissau","GY":"Guyana","HT":"Haiti","HM":"Heard Island and McDonald Islands","HN":"Honduras","HK":"Hong Kong SAR China","HU":"Hungary","IS":"Iceland","IN":"India","ID":"Indonesia","IR":"Iran","IQ":"Iraq","IE":"Ireland","IM":"Isle of Man","IL":"Israel","IT":"Italy","JM":"Jamaica","JP":"Japan","JE":"Jersey","JT":"Johnston Island","JO":"Jordan","KZ":"Kazakhstan","KE":"Kenya","KI":"Kiribati","KW":"Kuwait","KG":"Kyrgyzstan","LA":"Laos","LV":"Latvia","LB":"Lebanon","LS":"Lesotho","LR":"Liberia","LY":"Libya","LI":"Liechtenstein","LT":"Lithuania","LU":"Luxembourg","MO":"Macau SAR China","MK":"Macedonia","MG":"Madagascar","MW":"Malawi","MY":"Malaysia","MV":"Maldives","ML":"Mali","MT":"Malta","MH":"Marshall Islands","MQ":"Martinique","MR":"Mauritania","MU":"Mauritius","YT":"Mayotte","FX":"Metropolitan France","MX":"Mexico","FM":"Micronesia","MI":"Midway Islands","MD":"Moldova","MC":"Monaco","MN":"Mongolia","ME":"Montenegro","MS":"Montserrat","MA":"Morocco","MZ":"Mozambique","MM":"Myanmar [Burma]","NA":"Namibia","NR":"Nauru","NP":"Nepal","NL":"Netherlands","AN":"Netherlands Antilles","NT":"Neutral Zone","NC":"New Caledonia","NZ":"New Zealand","NI":"Nicaragua","NE":"Niger","NG":"Nigeria","NU":"Niue","NF":"Norfolk Island","KP":"North Korea","VD":"North Vietnam","MP":"Northern Mariana Islands","NO":"Norway","OM":"Oman","PC":"Pacific Islands Trust Territory","PK":"Pakistan","PW":"Palau","PS":"Palestinian Territories","PA":"Panama","PZ":"Panama Canal Zone","PG":"Papua New Guinea","PY":"Paraguay","YD":"People's Democratic Republic of Yemen","PE":"Peru","PH":"Philippines","PN":"Pitcairn Islands","PL":"Poland","PT":"Portugal","PR":"Puerto Rico","QA":"Qatar","RO":"Romania","RU":"Russia","RW":"Rwanda","RE":"R\u00e9union","BL":"Saint Barth\u00e9lemy","SH":"Saint Helena","KN":"Saint Kitts and Nevis","LC":"Saint Lucia","MF":"Saint Martin","PM":"Saint Pierre and Miquelon","VC":"Saint Vincent and the Grenadines","WS":"Samoa","SM":"San Marino","SA":"Saudi Arabia","SN":"Senegal","RS":"Serbia","CS":"Serbia and Montenegro","SC":"Seychelles","SL":"Sierra Leone","SG":"Singapore","SK":"Slovakia","SI":"Slovenia","SB":"Solomon Islands","SO":"Somalia","ZA":"South Africa","GS":"South Georgia and the South Sandwich Islands","KR":"South Korea","ES":"Spain","LK":"Sri Lanka","SD":"Sudan","SR":"Suriname","SJ":"Svalbard and Jan Mayen","SZ":"Swaziland","SE":"Sweden","CH":"Switzerland","SY":"Syria","ST":"S\u00e3o Tom\u00e9 and Pr\u00edncipe","TW":"Taiwan","TJ":"Tajikistan","TZ":"Tanzania","TH":"Thailand","TL":"Timor-Leste","TG":"Togo","TK":"Tokelau","TO":"Tonga","TT":"Trinidad and Tobago","TN":"Tunisia","TR":"Turkey","TM":"Turkmenistan","TC":"Turks and Caicos Islands","TV":"Tuvalu","UM":"U.S. Minor Outlying Islands","PU":"U.S. Miscellaneous Pacific Islands","VI":"U.S. Virgin Islands","UG":"Uganda","UA":"Ukraine","SU":"Union of Soviet Socialist Republics","AE":"United Arab Emirates","GB":"United Kingdom","US":"United States","ZZ":"Unknown or Invalid Region","UY":"Uruguay","UZ":"Uzbekistan","VU":"Vanuatu","VA":"Vatican City","VE":"Venezuela","VN":"Vietnam","WK":"Wake Island","WF":"Wallis and Futuna","EH":"Western Sahara","YE":"Yemen","ZM":"Zambia","ZW":"Zimbabwe","AX":"\u00c5land Islands"};
function sourceValues() {
var values = [];
$.each(source, function(e){
values.push(source[e]);
});
return values;
}
var sourceNames = sourceValues();
</script>
</head>
<body>
<!--body-->
<div class="container">
<div class="page-header">
<h1>Meta Input</h1>
<div class="pull-right" style="position: relative; top: -40px;">
by <a href="https://github.com/jakulov" target="_blank">@jakulov</a>
</div>
</div>
<div class="jumbotron">
<p class="lead">
jQuery plugin, allows you to easily customize html input's and select's into user friendly ui-widgets,
with autocomplete, ajax-search, choosing multiple options and custom suggest template.
</p>
<div>
<a class="btn btn-lg btn-primary" href="https://github.com/jakulov/meta-input" target="_blank">
<i class="glyphicon glyphicon-list"></i>
Source on GitHub
</a>
<a class="btn btn-lg btn-warning" href="#examples">
<i class="glyphicon glyphicon-eye-open"></i>
Live demo & docs
</a>
<a class="btn btn-lg btn-default" href="https://github.com/jakulov/meta-input/archive/v0.1.2.zip">
<i class="glyphicon glyphicon-download-alt"></i>
Download .zip (v0.1.2)
</a>
</div>
<a name="examples"></a>
</div>
<div class="row">
<div class="col col-md-6">
<ol>
<small>Contents:</small>
<li><a href="#p1">Simple autocomplete</a></li>
<li><a href="#p1">Multiple choose</a></li>
<li><a href="#p2">Using with select tag</a></li>
<li><a href="#p2">Ajax data source</a></li>
<li><a href="#p3">Setting value</a></li>
<li><a href="#p3">Customize suggest template</a></li>
<li><a href="#p4">Options reference</a></li>
</ol>
</div>
</div>
<a name="p1"></a>
<hr>
<div class="row">
<div class="col col-md-6">
<h2>1. Simple autocomplete</h2>
<div class="example">
<input type="text" name="example1" placeholder="Type to search" id="example1" class="form-control">
<script>
$(function(){
$('#example1').meta_input({data: sourceNames});
});
</script>
</div>
<div class="explain">
Simple autocomplete on input tag with default options.
We only need to set data for widget. Code snippet:
<p>
<pre class="javascript"><code>$('#example1').meta_input({data: [
"Afganistan",
"Albalia",
"Austria",
...
]});
</code></pre>
</p>
</div>
</div>
<div class="col col-md-6">
<h2>2. Multiple choose</h2>
<div class="example">
<input type="text" name="example2" placeholder="Type to search" id="example2" class="form-control">
<script>
$(function(){
$('#example2').meta_input({data: sourceNames, multiple: true, customValues: true});
});
</script>
</div>
<div class="explain">
Autocomplete on input with "multiple" option. <br>Code snippet:
<p>
<pre class="javascript"><code>$('#example2').meta_input({data: [
"Afganistan",
"Albalia",
...
], multiple: true, customValues: true});
</code></pre>
</p>
<small>Here you can also see extra option "customValues" - it allows user to input custom values, that's not in data list</small>
</div>
</div>
</div>
<a name="p2"></a>
<hr>
<div class="row">
<div class="col col-md-6">
<h2>3. Using with <select></h2>
<div class="example">
<select name="example3" id="example3" class="form-control">
<option value="1">Option One</option>
<option value="2">Option Two</option>
<option value="3">Option Three</option>
<option value="4">Option Four</option>
<option value="5">Option Five</option>
<option value="6">Option Six</option>
<option value="7">Option Seven</option>
<option value="8">Option Eight</option>
<option value="9">Option Nine</option>
<option value="10">Option Ten</option>
</select>
<script>
$(function(){
$('#example3').meta_input();
});
</script>
</div>
<div class="explain">
Using with select tag is even more simple:
<p>
<pre class="javascript"><code>$('#example3').meta_input();
</code></pre>
</p>
<small>No any options required, cause data option automaticly creates from select options.<br><br> Also using with select tag has a different behaviour: suggest shows even if there's no term to search. You can have this affect on input tag to by using "select" option</small>
</div>
</div>
<div class="col col-md-6">
<h2>4. Ajax search</h2>
<div class="example">
<input type="text" name="example4" placeholder="Type to search" id="example4" class="form-control">
<script>
$(function(){
$('#example4').meta_input({ajax: 'example.json'});
});
</script>
</div>
<div class="explain">
Using ajax request to search data on server. This use case is simple too. All search logic should be implemented on server side. Code snippet:
<p>
<pre class="javascript"><code>$('#example2').meta_input({ajax: 'example.json'});
</code></pre>
</p>
<small>This code will call URL <code>example.json?term=<i>user_input</i></code></small><br>
<small>Server should return ajax., formatted like this:</small>
<p><pre class="json"><code>{"data": [
{"id": "1", "name": "Option One"},
...
]}</code></pre></p>
</div>
</div>
</div>
<a name="p3"></a>
<hr>
<div class="row">
<div class="col col-md-6">
<h2>5. Setting value</h2>
<div class="example">
<input type="text" name="example5_1" placeholder="Type to search" id="example5_1" class="form-control" value="Ukraine">
<script>
$(function(){
$('#example5_1').meta_input({data: sourceNames});
});
</script>
</div>
<div class="explain">
Setting value for widget with single value (using value attribute):
<p><pre class="javascript"><code style="font-size: 10px;"><input type="text" placeholder="Type to search" id="example5_1" value="Ukraine">
<script>
$(function(){
$('#example5_1').meta_input({data: ["USA", "Ukraine", ...]});
});
</script></code></pre></p>
</div>
<div class="example">
<input type="text" name="example5_2" placeholder="Type to search" id="example5_2" class="form-control">
<script>
$(function(){
var sourceAlt = [
{"id": "1", "name": "Option One"},
{"id": "2", "name": "Option Two"},
{"id": "3", "name": "Option Three"},
{"id": "4", "name": "Option Four"},
{"id": "5", "name": "Option Five"},
{"id": "6", "name": "Option Six"},
{"id": "7", "name": "Option Seven"},
{"id": "8", "name": "Option Eight"},
{"id": "9", "name": "Option Nine"},
{"id": "10", "name": "Option Ten"}
];
$('#example5_2').meta_input({data: sourceAlt, value: {id: "1", name: "Option One"}});
});
</script>
</div>
<div class="explain">
Setting value for widget with single value object with id:
<p><pre class="javascript"><code style="font-size: 10px;">$('#example5_2').meta_input({
data: [
{"id": "1", "name": "Option One"},
{"id": "2", "name": "Option Two"},
],
value: {id: "1", name: "Option One"}
});</code></pre></p>
</div>
<div class="example">
<input type="text" name="example5_3" placeholder="Type to search" id="example5_3" class="form-control" value="">
<script>
$(function(){
$('#example5_3').meta_input({data: sourceNames, value: ["Ukraine", "Russia"], multiple: true});
});
</script>
</div>
<div class="explain">
Setting value for widget with miltiple values:
<p><pre class="javascript"><code style="font-size: 10px;">$('#example5_3').meta_input({
data: ["USA", "Ukraine", ...],
value: ["Ukraine", "Russia"], multiple: true
});</code></pre></p>
</div>
<div class="example">
<select name="example5_4" id="example5_4" multiple>
<option value="1">Option 1</option>
<option value="2" selected>Option 2</option>
<option value="3">Option 3</option>
<option value="4" selected>Option 4</option>
</select>
<script>
$(function(){
$('#example5_4').meta_input();
});
</script>
</div>
<div class="explain">
Select options with <b>selected</b> attribute also work fine!
</div>
</div>
<div class="col col-md-6">
<h2>6. Customize suggest</h2>
<div class="example">
<input type="text" name="example6" placeholder="Type to search" id="example6" class="form-control" value="">
<script>
$(function(){
var sourcePeople = [
{id:"1", name:"Mark Zukerberg","company":"Facebook", "pic":"http://meta-input.jakulov.ru/images/pic1.jpg"},
{id:"2", name:"Matt Cuts","company":"Google", "pic":"http://meta-input.jakulov.ru/images/pic2.jpeg"},
{id:"3", name:"Steve Jobs","company":"Apple", "pic":"http://meta-input.jakulov.ru/images/pic3.jpeg"},
{id:"4", name:"Ilya Segalovich","company":"Yandex", "pic":"http://meta-input.jakulov.ru/images/pic4.jpg"},
{id:"5", name:"Alexandr Volozh","company":"Yandex", "pic":"http://meta-input.jakulov.ru/images/pic5.jpg"},
{id:"6", name:"Sergey Brin","company":"Google", "pic":"http://meta-input.jakulov.ru/images/pic6.jpeg"},
];
$('#example6').meta_input({data: sourcePeople, suggestTemplate: '<table class="custom-suggest"><tr><td><img src="{{pic}}"></td><td><b>{{name}}</b><small>{{company}}</small></td></tr></table>'});
});
</script>
</div>
<div class="explain">
It's pretty easy to use custom templates for rendering suggest items.<br>
You can fully specify your own html template, using for render single suggest item.
For example, we want to view person's suggest list with photos and some extra information.
It's doing like this:
<p><pre class="javascript"><code>var sourcePeople = [
{
id:"1",
name:"Mark Zukerberg",
company:"Facebook",
pic:"img/pic1.jpg"
},
{
id:"2",
name:"Matt Cuts",
company:"Google",
pic:"img/pic2.jpeg"
},
...
];
$('#example6').meta_input({
data: sourcePeople,
suggestTemplate: '<table class="custom-suggest"><tr><td><img src="{{pic}}"></td><td><b>{{name}}</b><small>{{company}}</small></td></tr></table>'
});</code></pre></p>
All template placeholders, like "{{some_key}}" will be replaced with item's some_key value. Than use your CSS skills, to get what you want. My example presented above.
</div>
</div>
</div>
<a name="p4"></a>
<hr>
<div class="row">
<div class="col col-md-12">
<h2>7. Options</h2>
<div>
<p>With help of options you can control most features of widget.</p>
<table class="table">
<thead>
<tr>
<th>option</th>
<th>type</th>
<th>description</th>
<th>default</th>
<th>note</th>
</tr>
</thead>
<tbody>
<tr>
<td><b>multiple</b></td>
<td>bool</td>
<td>Allow to select multiple values</td>
<td><code>false</code></td>
<td><small>can be set to <code>true</code> with tag attribute "multiple". Be sure to use name attribute like "name[]" to receive multiple values after form submittingg</small></td>
</tr>
<tr>
<td><b>data</b></td>
<td>array</td>
<td>Data for autocomplete</td>
<td><code>[]</code></td>
<td><small>Can be used in format: <code>['Option 1', 'Option 2' ...]</code> <br>
or <code>[{id:1, name:'Option 1'}, {id:2, name:'Option 2' ...}]</code>. <br>
Objects in array also can contain extra fields</small></td>
</tr>
<tr>
<td><b>value</b></td>
<td>array|object|string</td>
<td>Pre selected value(s)</td>
<td><code>null</code></td>
<td><small>Can be used in format: <code>'Option 1'</code>, <code>['Option 1', 'Option 2' ...]</code> <br>
or <code>[{id:1, name:'Option 1'}, {id:2, name:'Option 2' ...}]</code>. <br>
For more see example #5</small></td>
</tr>
<tr>
<td><b>ajax</b></td>
<td>string</td>
<td>Call <code>$.getJSON(ajax, {term: term})</code> for getting data for autocomplete.</td>
<td><code>''</code></td>
<td><small>Cannot be used with select tags</small></td>
</tr>
<tr>
<td><b>match</b></td>
<td>array</td>
<td>Which fields of data item object should be matched against term.</td>
<td><code>['name']</code></td>
<td><small></small></td>
</tr>
<tr>
<td><b>matchFirst</b></td>
<td>bool</td>
<td>Match term only with string's start.</td>
<td><code>false</code></td>
<td><small></small></td>
</tr>
<tr>
<td><b>filterSame</b></td>
<td>bool</td>
<td>Hide already selected items.</td>
<td><code>true</code></td>
<td><small></small></td>
</tr>
<tr>
<td><b>limit</b></td>
<td>int</td>
<td>Limit of shown matched data items.</td>
<td><code>100</code></td>
<td><small></small></td>
</tr>
<tr>
<td><b>inputTimeout</b></td>
<td>int</td>
<td>Timeout (in milliseconds) between user presses key and widget starts to search suggests.</td>
<td><code>400</code></td>
<td><small></small></td>
</tr>
<tr>
<td><b>select</b></td>
<td>bool</td>
<td>Allow select options without type term to search</td>
<td><code>false</code></td>
<td><small>When using with select tag, it's always sets to <code>true</code></small></td>
</tr>
<tr>
<td><b>customValues</b></td>
<td>bool</td>
<td>Allow user to select value, that's not in the list of options</td>
<td><code>false</code></td>
<td><small>When using with select tag, it's always sets to <code>false</code></small></td>
</tr>
<tr>
<td><b>selectPlaceholder</b></td>
<td>string</td>
<td>Placeholder in input, when using with select tag</td>
<td><code>'Type to filter'</code></td>
<td><small>With input tag it's used placeholder from tag</small></td>
</tr>
<tr>
<td><b>suggestTemplate</b></td>
<td>string</td>
<td>HTML template for formatting suggest item. Substrings like "{{key}}" will be replaceed with data item key</td>
<td><code>'{{name}}'</code></td>
<td><small>See more in example #6</small></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<hr>
<div class="row" style="text-align: center;">
<a href="#" class="btn btn-lg btn-default"><i class="glyphicon glyphicon-arrow-up"></i> Back to top</a>
</div>
<hr>
<div class="row">
<div class="col col-md-10">
Shared with <a href="http://opensource.org/licenses/MIT" target="_blank">MIT Licence</a>
</div>
<div class="col col-md-2">
© <a href="http://jakulov.ru">jakulov.ru</a>
</div>
</div>
<hr>
</div>
<!--footer-->
</body>
</html>