Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chosen Search Ajax

Chosen Search Ajax is a plugin built on the top of Chosen v1.8.7 plugin to add search by ajax in the select options.

Please refer to https://harvesthq.github.io/chosen/ for more information about chosen and it's options.

Demo

Usage

Import these files

<!-- 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>

To use it call [ chosen_ajax ] function and you can use any of chosen options. But it is mandatory to set [ ajax_base_url ] which is the server url.

$(".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
});

After finishing the search e.x.

select id, name from customers where countries like %{$_GET[search]}%

The server must return a JSON array as a response in this structure

[
    [value, label],
    [value, label],
    [value, label],
] 
e.x.
[
    ['EG', 'Egypt'],
    ['US', 'United Stated'],
    ['UK', 'United Kingdom'],
]   

Author

Ahmed Samir

Contacts: eng.ahmed.samir.fci@gmail.com | Linkedin

About

Chosen Search Ajax is a plugin built on the top of Chosen v1.8.7 plugin to add search by ajax in the select options. Please refer to https://harvesthq.github.io/chosen/ for more information about chosen and it's options.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages