-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
114 lines (106 loc) · 5.12 KB
/
Copy pathindex.html
File metadata and controls
114 lines (106 loc) · 5.12 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chosen Search Ajax</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/chosen.min.css">
</head>
<body>
<div class="container" id="container">
<div class="alert-info">
<h1>Chosen Search Ajax</h1>
</div>
<div id="content">
<p>Chosen Search Ajax is a plugin built on the top of <a href="https://harvesthq.github.io/chosen/" target="blanck">Chosen v1.8.7</a> plugin to add search by ajax in the select options.</p>
<p>Please refer to <a href="https://harvesthq.github.io/chosen/" target="blanck">https://harvesthq.github.io/chosen/</a> for more information about chosen and it's options.</p>
<br/>
<h5 class="alert-warning">Try search for any country e.x. Chana, Canada, Brazil ... Type at least two characters</h5>
<div class="form-group">
<label for="single-country-elem">Single Country: </label>
<select data-placeholder="Choose a Country..." class="form-control chosen-select" id="single-country-elem">
<option value=""></option>
<option value="Egypt" selected="">Egypt</option>
</select>
</div>
<br/>
<br/>
<div class="form-group">
<label for="multiple-country-elem">Multiple Countries: </label>
<select name="ss" data-placeholder="Choose a Country..." class="form-control chosen-select" id="multiple-country-elem" multiple>
<option value=""></option>
<option value="United States" selected="">United States</option>
<option value="United Kingdom" selected="">United Kingdom</option>
</select>
</div>
</div>
<div>
<div class="panel panel-danger">
<div class="panel-heading">
Usage
</div>
<div class="panel-body">
<h4>Import these files</h4>
<pre>
<!-- CSS -->
<link rel="stylesheet" href="css/chosen.min.css">
<!-- JS -->
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/chosen.jquery.min.js" type="text/javascript"></script>
<script src="js/chosen_ajax.js" type="text/javascript"></script>
</pre>
<br/>
<h4>To use it call chosen_ajax function and you can use any of <a href="https://harvesthq.github.io/chosen/options.html">chosen options</a>. But it is mandatory to set ajax_base_url which is the server url.</h4>
<pre>
$(".chosen-select").chosen_ajax({
allow_single_deselect: true, // Normal chosen option
// Ajax options
ajax_base_url: "http://asamir.local/chosen-search-ajax-plugin/server.php", // Mandatory
ajax_method: "POST", // Default GET
ajax_data: {type: 'A', extra: 123456789}, // To set extra data + {search field}
ajax_min_chars: 2 // Minimum characters to send ajax request
});
</pre>
<br/>
<h4>After finishing the search e.x.</h4>
<pre>
select id, name from customers where countries like %{$_GET[search]}%
</pre>
<h4>The server must return a JSON array as a response in this structure</h4>
<pre>
[
[value, label],
[value, label],
[value, label],
]
e.x.
[
['EG', 'Egypt'],
['US', 'United Stated'],
['UK', 'United Kingdom'],
]
</pre>
</div>
<div class="panel-footer">
</div>
</div>
</div>
<div style="text-align: center; padding: 5px; bottom: 0px; width: 100%" class="alert-success">
<h5><a href="#">Ahmed Samir</a> | <a href="https://github.com/engahmed99/chosen-search-ajax-plugin">GitHub</a></h5>
</div>
</div>
<script src="js/jquery-1.12.4.min.js" type="text/javascript"></script>
<script src="js/chosen.jquery.min.js" type="text/javascript"></script>
<script src="js/chosen_ajax.js" type="text/javascript"></script>
<script>
$(".chosen-select").chosen_ajax({
allow_single_deselect: true, // Normal chosen option
// Ajax options
ajax_base_url: "http://asamir.local/chosen-search-ajax-plugin/server.php", // Mandatory
ajax_method: "POST", // Default GET
ajax_data: {type: 'A', extra: 123456789}, // To set extra data + {search & value fields}
ajax_min_chars: 2 // Minimum characters to send ajax request
});
</script>
</body>
</html>