Regular <select> input is nice, but quite limited. For example, it is hard to use this control on a large set of options. To provide a solution, I have implemented drop down list based on a text input filed but with a dynamic list of options that gets filtered as you type.
xxxxxxxxxx
<div class="w2ui-field">
<label>List:</label>
<div> <input type="list"> <span class="legend">Cannot type any text, but only items from the list</span> </div>
</div>
<div style="height: 10px"></div>
<div class="w2ui-field">
<label>Combo:</label>
<div> <input type="combo"> <span class="legend">You can type any text</span> </div>
</div>
<div style="height: 20px"></div>
<script>
$(function () {
var people = ['George Washington', 'John Adams', 'Thomas Jefferson', 'James Buchanan', 'James Madison', 'Abraham Lincoln', 'James Monroe', 'Andrew Johnson', 'John Adams', 'Ulysses Grant', 'Andrew Jackson', 'Rutherford Hayes', 'Martin Van Buren', 'James Garfield', 'William Harrison', 'Chester Arthur', 'John Tyler', 'Grover Cleveland', 'James Polk', 'Benjamin Harrison', 'Zachary Taylor', 'Grover Cleveland', 'Millard Fillmore', 'William McKinley', 'Franklin Pierce', 'Theodore Roosevelt', 'John Kennedy', 'William Howard', 'Lyndon Johnson', 'Woodrow Wilson', 'Richard Nixon', 'Warren Harding', 'Gerald Ford', 'Calvin Coolidge', 'James Carter', 'Herbert Hoover', 'Ronald Reagan', 'Franklin Roosevelt', 'George Bush', 'Harry Truman', 'William Clinton', 'Dwight Eisenhower', 'George W. Bush', 'Barack Obama'];
$('input[type=list]').w2field('list', { items: people });
$('input[type=combo]').w2field('combo', { items: people });
});
</script>
xxxxxxxxxx
options = {
items : [], // array of item objects, can be a function
selected : {}, // selected object
url : null, // url to pull data from (can support similar format as w2grid)
method : null, // default comes from w2utils.settings.dataType
postData : {}, // additional data to submit to URL
minLength : 1, // min search length to trigger reload from URL
cacheMax : 250, // number of items to cache if retrieved from URL
maxDropHeight : 350, // max height for drop down menu
maxDropWidth : null, // max width for drop down menu
match : 'begins', // ['contains', 'is', 'begins', 'ends']
silent : true, // indicates if to display error tag
icon : null, // icon class for selected item
iconStyle : '', // icon style for selected item
onSearch : null, // when search needs to be performed
onRequest : null, // when request is submitted
onLoad : null, // when data is received
onError : null, // when data fails to load due to server error or other failure modes
onIconClick : null, // when icon is clicked
renderDrop : null, // render function for drop down item
compare : null, // compare functtion while searching
filter : true, // filter as user types
prefix : '', // prefix for control
suffix : '', // suffix for control
msgNoItems : '', // message when nothing found, can be a function
openOnFocus : false, // if to show overlay onclick or when typing
markSearch : false, // indicated if to mark search string in the drop down
recId : null, // map retrieved data from url to id, can be string or function
recText : null, // map retrieved data from url to text, can be string or function
};
xxxxxxxxxx
options = {
id : '', // unique id
text : '', // item text
icon : '', // icon class if any
img : '', // image class if any
disabled : false, // indicates if disabled
hidden : false, // indicates if hidden
count : null // count to display on the right
};
xxxxxxxxxx
$('input[type=combo]').data('selected', { id: 1, text: 'Some text'}).change();
// or
$('input[type=combo]').w2field().set({ id: 1, text: 'Some text'});
xxxxxxxxxx
$('input[type=combo]').data('selected', { id: 1, text: 'Some text'}).data('w2field').refresh();