here is the patch, for preselecting the first item in the auto complete list.


Index: 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
===================================================================
--- 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
 (revision 541579)
+++ 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/AbstractAutoCompleteBehavior.java
 (working copy)
@@ -34,6 +34,7 @@
  private static final ResourceReference AUTOCOMPLETE_JS = new 
CompressedResourceReference(
    AutoCompleteBehavior.class, "wicket-autocomplete.js");
 
+ protected boolean preselect = false;
  /**
   * 
   */
@@ -66,7 +67,7 @@
   Response response = getComponent().getResponse();
   final String id = getComponent().getMarkupId();
   response.write(JavascriptUtils.SCRIPT_OPEN_TAG);
-  response.write("new Wicket.AutoComplete('" + id + "','" + getCallbackUrl() + 
"');");
+  response.write("new Wicket.AutoComplete('" + id + "','" + getCallbackUrl() 
+"',"+ preselect + ");");
   response.write(JavascriptUtils.SCRIPT_CLOSE_TAG);
  }
 
Index: 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteBehavior.java
===================================================================
--- 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteBehavior.java
 (revision 541579)
+++ 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteBehavior.java
 (working copy)
@@ -49,6 +49,19 @@
   */
  public AutoCompleteBehavior(IAutoCompleteRenderer renderer)
  {
+  this(renderer, false);
+ }
+
+
+ /**
+  * Constructor
+  * 
+  * @param renderer
+  *            renderer that will be used to generate output
+  * @param preselect 
+  */
+ public AutoCompleteBehavior(IAutoCompleteRenderer renderer, boolean preselect)
+ {
   if (renderer == null)
   {
    throw new IllegalArgumentException("renderer cannot be null");
@@ -54,6 +67,7 @@
    throw new IllegalArgumentException("renderer cannot be null");
   }
   this.renderer = renderer;
+  this.preselect = preselect;
  }
 
 
Index: 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteTextField.java
===================================================================
--- 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteTextField.java
 (revision 541579)
+++ 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/AutoCompleteTextField.java
 (working copy)
@@ -43,7 +43,7 @@
   */
  public AutoCompleteTextField(String id, Class type)
  {
-  this(id, (IModel)null, type);
+  this(id, (IModel)null, type,false);
  }
 
  /**
@@ -50,10 +50,11 @@
   * @param id
   * @param model
   * @param type
+  * @param preselect 
   */
- public AutoCompleteTextField(String id, IModel model, Class type)
+ public AutoCompleteTextField(String id, IModel model, Class type,boolean 
preselect)
  {
-  this(id, model, type, StringAutoCompleteRenderer.INSTANCE);
+  this(id, model, type, StringAutoCompleteRenderer.INSTANCE,preselect);
 
  }
 
@@ -60,10 +61,21 @@
  /**
   * @param id
   * @param object
+  * @param preselect 
+  */
+ public AutoCompleteTextField(String id, IModel object,boolean preselect)
+ {
+  this(id, object, (Class)null,preselect);
+ }
+
+ 
+ /**
+  * @param id
+  * @param object
   */
  public AutoCompleteTextField(String id, IModel object)
  {
-  this(id, object, (Class)null);
+  this(id, object, (Class)null,false);
  }
 
  /**
@@ -68,10 +80,20 @@
 
  /**
   * @param id
+  * @param preselect 
+  */
+ public AutoCompleteTextField(String id,boolean preselect)
+ {
+  this(id, (IModel)null,preselect);
+
+ }
+ 
+ /**
+  * @param id
   */
  public AutoCompleteTextField(String id)
  {
-  this(id, (IModel)null);
+  this(id, (IModel)null,false);
 
  }
 
@@ -91,7 +113,7 @@
   */
  public AutoCompleteTextField(String id, Class type, IAutoCompleteRenderer 
renderer)
  {
-  this(id, null, type, renderer);
+  this(id, null, type, renderer,false);
  }
 
  /**
@@ -101,7 +123,7 @@
   */
  public AutoCompleteTextField(String id, IModel model, IAutoCompleteRenderer 
renderer)
  {
-  this(id, model, (Class)null, renderer);
+  this(id, model, (Class)null, renderer,false);
  }
 
  /**
@@ -109,8 +131,9 @@
   * @param model
   * @param type
   * @param renderer
+  * @param preselect 
   */
- public AutoCompleteTextField(String id, IModel model, Class type, 
IAutoCompleteRenderer renderer)
+ public AutoCompleteTextField(String id, IModel model, Class type, 
IAutoCompleteRenderer renderer,boolean preselect)
  {
   super(id, model, type);
 
@@ -117,7 +140,7 @@
   // this disables Firefox autocomplete
   add(new SimpleAttributeModifier("autocomplete","off"));
   
-  add(new AutoCompleteBehavior(renderer)
+  add(new AutoCompleteBehavior(renderer,preselect)
   {
 
    private static final long serialVersionUID = 1L;
Index: 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
===================================================================
--- 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
 (revision 541579)
+++ 
C:/wicket/wicket-svn/releases/wicket-1.2.6/wicket-extensions/src/main/java/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js
 (working copy)
@@ -7,7 +7,7 @@
 if (typeof(Wicket) == "undefined")
  Wicket = { };
 
-Wicket.AutoComplete=function(elementId,callbackUrl){
+Wicket.AutoComplete=function(elementId,callbackUrl,preselect){
     var KEY_BACKSPACE=8;
     var KEY_TAB=9;
     var KEY_ENTER=13;
@@ -167,8 +167,12 @@
     }
 
     function updateChoices(){
-        selected=-1;
-
+        if(preselect==true){
+         selected = 0;
+        }
+        else{
+         selected=-1;
+        }        
         var value = wicketGet(elementId).value;
         var request = new 
Wicket.Ajax.Request(callbackUrl+"&q="+processValue(value), doUpdateChoices, 
false, true, false, "wicket-autocomplete|d");
         request.get();



  ----- Original Message ----- 
  From: Ryan Gravener 
  To: wicket-user@lists.sourceforge.net 
  Sent: Tuesday, May 29, 2007 12:57 PM
  Subject: Re: [Wicket-user] Autocomplete - selecting (higlighting)firstoption 
by default.


  If you can, submit a patch.  I think most of the community would like that 
functionality.


  On 29/05/07, Dipu < [EMAIL PROTECTED]> wrote:
    I agree, it will be nice to have the ability control this.
    In my case i had to hard code it in the autocomplete js file and i had to 
rebuild the wicket extensions.

    Regards
    Dipu


      ----- Original Message ----- 
      From: Sean Sullivan 
      To: wicket-user@lists.sourceforge.net 
      Sent: Saturday, May 26, 2007 6:57 AM
      Subject: Re: [Wicket-user] Autocomplete - selecting (higlighting) 
firstoption by default.



      IMHO, it would be nice if Java programmers could control this behavior 
with a Java API.


       
      On 5/25/07, Dipu <[EMAIL PROTECTED]> wrote: 


        At the moment with Wicket's auto complete list  we need to scroll down 
to select an option from the Autocomplete list. 
        It would be nice to have the first item highlighted by default.

        I tried changing selected to 0 where its declared and it didn't work 
for me.

        On setting selected to 0 a doUpdateChoices(resp) worked,

        function doUpdateChoices(resp){
        var element = getAutocompleteMenu();
        element.innerHTML=resp;
        if(element.firstChild && element.firstChild.childNodes) {
        selected = 0;

        Can anyone please confirm if this is the right way to go.

        Regards
        Dipu





--------------------------------------------------------------------------


      -------------------------------------------------------------------------
      This SF.net email is sponsored by DB2 Express
      Download DB2 Express C - the FREE version of DB2 express and take
      control of your XML. No limits. Just data. Click to get it now.
      http://sourceforge.net/powerbar/db2/ 


--------------------------------------------------------------------------


      _______________________________________________
      Wicket-user mailing list
      Wicket-user@lists.sourceforge.net
      https://lists.sourceforge.net/lists/listinfo/wicket-user




    -------------------------------------------------------------------------
    This SF.net email is sponsored by DB2 Express
    Download DB2 Express C - the FREE version of DB2 express and take
    control of your XML. No limits. Just data. Click to get it now. 
    http://sourceforge.net/powerbar/db2/
    _______________________________________________
    Wicket-user mailing list 
    Wicket-user@lists.sourceforge.net
    https://lists.sourceforge.net/lists/listinfo/wicket-user





  -- 
  Ryan Gravener
  fbb55c59d619f3cd68ac4f70ebeca372 


------------------------------------------------------------------------------


  -------------------------------------------------------------------------
  This SF.net email is sponsored by DB2 Express
  Download DB2 Express C - the FREE version of DB2 express and take
  control of your XML. No limits. Just data. Click to get it now.
  http://sourceforge.net/powerbar/db2/


------------------------------------------------------------------------------


  _______________________________________________
  Wicket-user mailing list
  Wicket-user@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/wicket-user
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to