Friday, November 11, 2011

Auto suggest box in cordys

var SEARCH_KEY = "";
---------------------------------------------------
application.importType("wcp.library.util.AutoSuggest");
application.importType("wcp.library.util.DataProvider");
application.addType(txtClientName, "wcp.library.util.AutoSuggest");
//Add required Autosuggest classes to the inputs
application.inherit(ClientsProvider, DataProvider)
txtClientName.registerDataProvider(new ClientsProvider());
-----------------------------------------------------------------

function ClientsProvider() {}
ClientsProvider.prototype.getSuggestions = function () {

var suggestions = null;
//read the current input vlaue if string length is less than 3 clear
var strValue = txtClientName.getValue();
if (strValue.length > 2 && SEARCH_KEY != strValue) {
//debugger;
// dont fire webservice again.. display the existing names' list if oldKey is the substr of newKey
if (strValue.toLowerCase().indexOf(SEARCH_KEY.toLowerCase()) != -1 && SEARCH_KEY != "") return NAME_LIST;
//empty the current name list and fill the new one
SEARCH_KEY = strValue;
suggestions = updateClientNameSuggestions(strValue);
NAME_LIST = suggestions;
}
return suggestions;
}
--------------------------------------
function Form_BeforeClose(eventObject) {
SEARCH_KEY = "";
}

2 comments:

Anonymous said...

function Form_InitDone(eventObject)
{
//import AutoSuggest library
application.importType("wcp.library.util.AutoSuggest");
application.importType("wcp.library.util.DataProvider");

//extend DataProvider
application.inherit(DataProviderFunction, DataProvider);
application.addType(autoInputID, "wcp.library.util.AutoSuggest");

//register data provider
autoInputID.registerDataProvider(new DataProviderFunction());
autoInputID.onkeyup=readSuggestions;
}
function readSuggestions()
{
if(autoInputID.getValue().length>2)
{
cordys.setTextContent(cordys.selectXMLNode(autoSuggestTrialModel.getMethodRequest("get"),".//*[local-name()='NAME']"),"%"+autoInputID.getValue()+"%")
autoSuggestTrialModel.reset();
}
}
function DataProviderFunction(){
this.DataProvider();
}
DataProviderFunction.prototype.getSuggestions = function()
{
var names = cordys.selectXMLNodes(autoSuggestTrialModel.getData(),".//*[local-name()='NAME']");
var suggestions = [];
for (var n=0, length=names.length; n<length; n++)
{
suggestions[n] = cordys.getTextContent(names[n]);
}
return suggestions;
}

sumit said...

change event not working with auto suggest ??
write in
form initdone()
{
input_id.addListener("onsuggest",order_Id_Change);

}

Post a Comment