Forum Moderators: open

Message Too Old, No Replies

YUI: Auto Complete for Full Name?

         

webgaya

4:29 am on Oct 23, 2008 (gmt 0)

10+ Year Member



I provided an array which contains full names to YUI. Then when someone
one type in the text box, it will suggest the name. For an example, if
someone types "J" and if a user exists called "Jack Bauer" then it
will suggest "Jack Bauer". But currently this only works for first
name. ie. if some one types "B" then "Jack Bauer" won't be suggested.

I want the suggestion to be done if the first letter of first name or
last name is typed. How can I get this done? Is there a particular
option to set? Version of the YUI I am using is 2.5.2. Below is the
code I am using in my template.

employee - is an array containing full names of employees (each full
name only contains first name and last name. No middle names.)

txtEmployeeSearch - is the name of the text box

employeeSearchACCon tainer - is the div where suggestion gets populated.

<script type="text/javascri pt">
YAHOO.OrangeHRM. autocomplete. ACJSArray = new function() {
// Instantiate first JS Array DataSource
this.oACDS = new YAHOO.widget. DS_JSArray( employees) ;

// Instantiate AutoComplete for txtEmployeeSearch
this.oAutoComp = new
YAHOO.widget. AutoComplete( 'txtEmployeeSear ch','employeeSea rchACContainer' ,
this.oACDS);
this.oAutoComp. prehighlightClas sName = "yui-ac-prehighligh t";
this.oAutoComp. typeAhead = false;
this.oAutoComp. useShadow = true;
this.oAutoComp. minQueryLength = 1;
this.oAutoComp. textboxFocusEven t.subscribe( function( ){
var sInputValue = YAHOO.util.Dom. get('txtEmployee Search'). value;
if(sInputValue. length === 0) {
var oSelf = this;
setTimeout(function (){oSelf. sendQuery( sInputValue) ;},0);
}
});
};
</script>

Fotiman

2:17 pm on Oct 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't think YUI 2.5.2 includes this behavior. YUI 2.6.0, however, allows you to specify queryMatchContains as a config option. It would find any matches, not just those at the beginning of words.