//create text box for auto-complete during email lookup in left grid var textBox = app.createTextBox().setName('textBox') .setWidth('330px').setId('textBox'); var tBoxHandler = app.createServerKeyHandler('search_'); tBoxHandler.addCallbackElement(textBox); textBox.addKeyUpHandler(tBoxHandler); ...function search_(e){ var app = UiApp.getActiveApplication(); app.getElementById('list').clear(); var searchKey = new RegExp(e.parameter.textBox,"gi"); if (searchKey == "") app.getElementById('textBox').setValue(''); var range = sheetOwner.getRange(1, 1, sheetOwner.getLastRow(), 2).getValues(); var listBoxCount = 0; var firstOne = true; for (var i in range){ // if first/last name available, display name and email address if (range[i][0].search(searchKey) != -1 || range[i][1].search(searchKey) != -1){ if (range[i][0].toString()){ app.getElementById('list').addItem(range[i][0].toString()+ ' .. '+range[i][1].toString(), range[i][1].toString()); var listBoxCount = listBoxCount + 1; } else { // else just display the email address app.getElementById('list').addItem(range[i][1].toString()); var listBoxCount = listBoxCount + 1; } if (firstOne) var firstItem = range[i][1].toString(); var firstOne = false; } } // set the top listbox item as the default if (listBoxCount > 0) app.getElementById('list').setItemSelected(0, true); // if enter key is pressed in text box, assume they want to add // the email that’s not in the list if (e.parameter.keyCode==13 && listBoxCount < 1 && searchKey !== "") { ...
Posted by Steve Webster, Dito
Want to weigh in on this topic? Discuss on Buzz